http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e43b7a87/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/AvoidUseOfAsKeywordRule.java ---------------------------------------------------------------------- diff --git a/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/AvoidUseOfAsKeywordRule.java b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/AvoidUseOfAsKeywordRule.java new file mode 100644 index 0000000..b16dbe1 --- /dev/null +++ b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/AvoidUseOfAsKeywordRule.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.adobe.ac.pmd.rules.maintanability; + +import com.adobe.ac.pmd.parser.IParserNode; +import com.adobe.ac.pmd.parser.NodeKind; +import com.adobe.ac.pmd.rules.core.AbstractAstFlexRule; +import com.adobe.ac.pmd.rules.core.ViolationPriority; + +public class AvoidUseOfAsKeywordRule extends AbstractAstFlexRule +{ + @Override + protected ViolationPriority getDefaultPriority() + { + return ViolationPriority.LOW; + } + + @Override + protected void visitRelationalExpression( final IParserNode ast ) + { + super.visitRelationalExpression( ast ); + + if ( ast.getChildren() != null ) + { + for ( final IParserNode child : ast.getChildren() ) + { + if ( child.is( NodeKind.AS ) ) + { + addViolation( child ); + } + } + } + } +}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e43b7a87/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/AvoidUsingPublicStaticFieldRule.java ---------------------------------------------------------------------- diff --git a/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/AvoidUsingPublicStaticFieldRule.java b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/AvoidUsingPublicStaticFieldRule.java new file mode 100644 index 0000000..39cdb90 --- /dev/null +++ b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/AvoidUsingPublicStaticFieldRule.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.adobe.ac.pmd.rules.maintanability; + +import java.util.List; + +import com.adobe.ac.pmd.nodes.IAttribute; +import com.adobe.ac.pmd.rules.core.AbstractAstFlexRule; +import com.adobe.ac.pmd.rules.core.ViolationPriority; + +/** + * @author xagnetti + */ +public class AvoidUsingPublicStaticFieldRule extends AbstractAstFlexRule +{ + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#findViolationsFromAttributes + * (java.util.List) + */ + @Override + protected void findViolationsFromAttributes( final List< IAttribute > variables ) + { + for ( final IAttribute attribute : variables ) + { + if ( attribute.isPublic() + && attribute.isStatic() && !attribute.getName().contains( "instance" ) ) + { + addViolation( attribute, + attribute.getName() ); + } + } + } + + /* + * (non-Javadoc) + * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority() + */ + @Override + protected ViolationPriority getDefaultPriority() + { + return ViolationPriority.HIGH; + } +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e43b7a87/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/AvoidUsingWithKeyWordRule.java ---------------------------------------------------------------------- diff --git a/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/AvoidUsingWithKeyWordRule.java b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/AvoidUsingWithKeyWordRule.java new file mode 100644 index 0000000..1c531ad --- /dev/null +++ b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/AvoidUsingWithKeyWordRule.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.adobe.ac.pmd.rules.maintanability; + +import java.util.List; + +import com.adobe.ac.pmd.nodes.IFunction; +import com.adobe.ac.pmd.parser.IParserNode; +import com.adobe.ac.pmd.rules.core.AbstractAstFlexRule; +import com.adobe.ac.pmd.rules.core.ViolationPriority; + +/** + * @author xagnetti + */ +public class AvoidUsingWithKeyWordRule extends AbstractAstFlexRule +{ + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#findViolations(com.adobe + * .ac.pmd.nodes.IFunction) + */ + @Override + protected void findViolations( final IFunction function ) + { + final List< IParserNode > withStatements = function.findPrimaryStatementsInBody( "with" ); + + for ( final IParserNode withStatement : withStatements ) + { + addViolation( withStatement ); + } + } + + /* + * (non-Javadoc) + * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority() + */ + @Override + protected ViolationPriority getDefaultPriority() + { + return ViolationPriority.HIGH; + } +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e43b7a87/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/ClassAndExtensionAreIdenticalRule.java ---------------------------------------------------------------------- diff --git a/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/ClassAndExtensionAreIdenticalRule.java b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/ClassAndExtensionAreIdenticalRule.java new file mode 100644 index 0000000..cea669b --- /dev/null +++ b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/ClassAndExtensionAreIdenticalRule.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.adobe.ac.pmd.rules.maintanability; + +import org.apache.commons.lang.StringUtils; + +import com.adobe.ac.pmd.nodes.IClass; +import com.adobe.ac.pmd.rules.core.AbstractAstFlexRule; +import com.adobe.ac.pmd.rules.core.ViolationPriority; + +/** + * @author xagnetti + */ +public class ClassAndExtensionAreIdenticalRule extends AbstractAstFlexRule +{ + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#findViolations(com.adobe + * .ac.pmd.nodes.IClass) + */ + @Override + protected final void findViolations( final IClass classNode ) + { + final String extensionName = classNode.getExtensionName(); + + if ( extensionName != null ) + { + final String extension = extractExtensionName( extensionName ); + + if ( extension.equals( classNode.getName() ) ) + { + addViolation( classNode ); + } + } + } + + /* + * (non-Javadoc) + * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority() + */ + @Override + protected final ViolationPriority getDefaultPriority() + { + return ViolationPriority.HIGH; + } + + private String extractExtensionName( final String extensionName ) + { + return extensionName.indexOf( '.' ) == -1 ? extensionName + : StringUtils.substringAfterLast( extensionName, + "." ); + } +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e43b7a87/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/DynamicClassRule.java ---------------------------------------------------------------------- diff --git a/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/DynamicClassRule.java b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/DynamicClassRule.java new file mode 100644 index 0000000..988db64 --- /dev/null +++ b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/DynamicClassRule.java @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.adobe.ac.pmd.rules.maintanability; + +import com.adobe.ac.pmd.nodes.IClass; +import com.adobe.ac.pmd.nodes.Modifier; +import com.adobe.ac.pmd.rules.core.AbstractAstFlexRule; +import com.adobe.ac.pmd.rules.core.ViolationPriority; + +/** + * @author xagnetti + */ +public class DynamicClassRule extends AbstractAstFlexRule +{ + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#isConcernedByTheCurrentFile + * () + */ + @Override + public final boolean isConcernedByTheCurrentFile() + { + return !getCurrentFile().isMxml(); + } + + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#findViolations(com.adobe + * .ac.pmd.nodes.IClass) + */ + @Override + protected final void findViolations( final IClass classNode ) + { + if ( classNode.is( Modifier.DYNAMIC ) ) + { + addViolation( classNode ); + } + } + + /* + * (non-Javadoc) + * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority() + */ + @Override + protected final ViolationPriority getDefaultPriority() + { + return ViolationPriority.HIGH; + } +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e43b7a87/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/EmptyStatementRule.java ---------------------------------------------------------------------- diff --git a/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/EmptyStatementRule.java b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/EmptyStatementRule.java new file mode 100644 index 0000000..a659f83 --- /dev/null +++ b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/EmptyStatementRule.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.adobe.ac.pmd.rules.maintanability; + +import com.adobe.ac.pmd.parser.IParserNode; +import com.adobe.ac.pmd.rules.core.AbstractAstFlexRule; +import com.adobe.ac.pmd.rules.core.ViolationPriority; + +/** + * @author xagnetti + */ +public class EmptyStatementRule extends AbstractAstFlexRule +{ + /* + * (non-Javadoc) + * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority() + */ + @Override + protected ViolationPriority getDefaultPriority() + { + return ViolationPriority.LOW; + } + + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#visitEmptyStatetement( + * com.adobe.ac.pmd.parser.IParserNode) + */ + @Override + protected void visitEmptyStatetement( final IParserNode statementNode ) + { + addViolation( statementNode ); + } +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e43b7a87/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/ExcessiveImportRule.java ---------------------------------------------------------------------- diff --git a/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/ExcessiveImportRule.java b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/ExcessiveImportRule.java new file mode 100644 index 0000000..becf73e --- /dev/null +++ b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/ExcessiveImportRule.java @@ -0,0 +1,80 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.adobe.ac.pmd.rules.maintanability; + +import com.adobe.ac.pmd.nodes.IPackage; +import com.adobe.ac.pmd.rules.core.ViolationPriority; +import com.adobe.ac.pmd.rules.core.thresholded.AbstractMaximizedAstFlexRule; + +/** + * @author xagnetti + */ +public class ExcessiveImportRule extends AbstractMaximizedAstFlexRule +{ + private static final int DEFAULT_THRESHOLD = 15; + private int importNumber; + + /* + * (non-Javadoc) + * @seecom.adobe.ac.pmd.rules.core.thresholded.IThresholdedRule# + * getActualValueForTheCurrentViolation() + */ + @Override + public final int getActualValueForTheCurrentViolation() + { + return importNumber; + } + + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.core.thresholded.IThresholdedRule#getDefaultThreshold + * () + */ + @Override + public final int getDefaultThreshold() + { + return DEFAULT_THRESHOLD; + } + + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#findViolations(com.adobe + * .ac.pmd.nodes.IPackage) + */ + @Override + protected final void findViolations( final IPackage packageNode ) + { + importNumber = packageNode.getImports().size(); + + if ( importNumber > getThreshold() ) + { + addViolation( packageNode.getClassNode() ); + } + } + + /* + * (non-Javadoc) + * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority() + */ + @Override + protected final ViolationPriority getDefaultPriority() + { + return ViolationPriority.NORMAL; + } +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e43b7a87/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/NonStaticConstantFieldRule.java ---------------------------------------------------------------------- diff --git a/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/NonStaticConstantFieldRule.java b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/NonStaticConstantFieldRule.java new file mode 100644 index 0000000..a322ecd --- /dev/null +++ b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/NonStaticConstantFieldRule.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.adobe.ac.pmd.rules.maintanability; + +import java.util.List; + +import com.adobe.ac.pmd.nodes.IConstant; +import com.adobe.ac.pmd.rules.core.AbstractAstFlexRule; +import com.adobe.ac.pmd.rules.core.ViolationPriority; + +/** + * @author xagnetti + */ +public class NonStaticConstantFieldRule extends AbstractAstFlexRule +{ + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#findViolationsFromConstants + * (java.util.List) + */ + @Override + protected final void findViolationsFromConstants( final List< IConstant > constants ) + { + for ( final IConstant field : constants ) + { + if ( !field.isStatic() + && field.isPublic() ) + { + addViolation( field, + field.getName() ); + } + } + } + + /* + * (non-Javadoc) + * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority() + */ + @Override + protected final ViolationPriority getDefaultPriority() + { + return ViolationPriority.LOW; + } +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e43b7a87/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/OnlyOneReturnRule.java ---------------------------------------------------------------------- diff --git a/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/OnlyOneReturnRule.java b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/OnlyOneReturnRule.java new file mode 100644 index 0000000..75f16f0 --- /dev/null +++ b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/OnlyOneReturnRule.java @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.adobe.ac.pmd.rules.maintanability; + +import com.adobe.ac.pmd.parser.IParserNode; +import com.adobe.ac.pmd.rules.core.AbstractAstFlexRule; +import com.adobe.ac.pmd.rules.core.ViolationPriority; + +/** + * @author xagnetti + */ +public class OnlyOneReturnRule extends AbstractAstFlexRule +{ + private int returnStatement; + + /* + * (non-Javadoc) + * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority() + */ + @Override + protected ViolationPriority getDefaultPriority() + { + return ViolationPriority.NORMAL; + } + + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#visitFunction(com.adobe + * .ac.pmd.parser.IParserNode, + * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule.FunctionType) + */ + @Override + protected void visitFunction( final IParserNode functionNode, + final FunctionType type ) + { + returnStatement = 0; + super.visitFunction( functionNode, + type ); + } + + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#visitReturn(com.adobe. + * ac.pmd.parser.IParserNode) + */ + @Override + protected void visitReturn( final IParserNode ast ) + { + returnStatement++; + + if ( returnStatement > 1 ) + { + addViolation( ast ); + } + } +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e43b7a87/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/ProtectedStaticMethodRule.java ---------------------------------------------------------------------- diff --git a/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/ProtectedStaticMethodRule.java b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/ProtectedStaticMethodRule.java new file mode 100644 index 0000000..0e67239 --- /dev/null +++ b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/ProtectedStaticMethodRule.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.adobe.ac.pmd.rules.maintanability; + +import com.adobe.ac.pmd.nodes.IFunction; +import com.adobe.ac.pmd.nodes.Modifier; +import com.adobe.ac.pmd.rules.core.AbstractAstFlexRule; +import com.adobe.ac.pmd.rules.core.ViolationPriority; + +/** + * @author xagnetti + */ +public class ProtectedStaticMethodRule extends AbstractAstFlexRule +{ + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#findViolations(com.adobe + * .ac.pmd.nodes.IFunction) + */ + @Override + protected void findViolations( final IFunction function ) + { + if ( function.is( Modifier.STATIC ) + && function.is( Modifier.PROTECTED ) ) + { + addViolation( function ); + } + } + + /* + * (non-Javadoc) + * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority() + */ + @Override + protected ViolationPriority getDefaultPriority() + { + return ViolationPriority.NORMAL; + } +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e43b7a87/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/ReferenceToVariableBindingFromItsInitializerRule.java ---------------------------------------------------------------------- diff --git a/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/ReferenceToVariableBindingFromItsInitializerRule.java b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/ReferenceToVariableBindingFromItsInitializerRule.java new file mode 100644 index 0000000..e62c3c6 --- /dev/null +++ b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/ReferenceToVariableBindingFromItsInitializerRule.java @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.adobe.ac.pmd.rules.maintanability; + +import java.util.List; + +import com.adobe.ac.pmd.nodes.IAttribute; +import com.adobe.ac.pmd.nodes.IConstant; +import com.adobe.ac.pmd.nodes.IField; +import com.adobe.ac.pmd.nodes.IFieldInitialization; +import com.adobe.ac.pmd.parser.IParserNode; +import com.adobe.ac.pmd.rules.core.AbstractAstFlexRule; +import com.adobe.ac.pmd.rules.core.ViolationPriority; + +/** + * @author xagnetti + */ +public class ReferenceToVariableBindingFromItsInitializerRule extends AbstractAstFlexRule +{ + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#findViolationsFromAttributes + * (java.util.List) + */ + @Override + protected void findViolationsFromAttributes( final List< IAttribute > variables ) + { + for ( final IAttribute attribute : variables ) + { + findViolation( attribute ); + } + } + + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#findViolationsFromConstants + * (java.util.List) + */ + @Override + protected void findViolationsFromConstants( final List< IConstant > constants ) + { + for ( final IConstant constant : constants ) + { + findViolation( constant ); + } + } + + /* + * (non-Javadoc) + * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority() + */ + @Override + protected ViolationPriority getDefaultPriority() + { + return ViolationPriority.HIGH; + } + + private void findViolation( final IField attribute ) + { + final IFieldInitialization initialization = attribute.getInitializationExpression(); + final String name = attribute.getName(); + + if ( initialization != null ) + { + final List< IParserNode > statements = initialization.getInternalNode() + .findPrimaryStatementsFromNameInChildren( new String[] + { name } ); + if ( statements != null + && !statements.isEmpty() ) + { + addViolation( attribute ); + } + } + } +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e43b7a87/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/TrueFalseConditionRule.java ---------------------------------------------------------------------- diff --git a/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/TrueFalseConditionRule.java b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/TrueFalseConditionRule.java new file mode 100644 index 0000000..e9ede97 --- /dev/null +++ b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/TrueFalseConditionRule.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.adobe.ac.pmd.rules.maintanability; + +import com.adobe.ac.pmd.parser.IParserNode; +import com.adobe.ac.pmd.rules.core.AbstractAstFlexRule; +import com.adobe.ac.pmd.rules.core.ViolationPriority; + +/** + * @author xagnetti + */ +public class TrueFalseConditionRule extends AbstractAstFlexRule // NO_UCD +{ + private static final int FALSE = 2; + private static final int TRUE = 1; + + /* + * (non-Javadoc) + * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority() + */ + @Override + protected ViolationPriority getDefaultPriority() + { + return ViolationPriority.HIGH; + } + + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#visitCondition(com.adobe + * .ac.pmd.parser.IParserNode) + */ + @Override + protected void visitCondition( final IParserNode condition ) + { + super.visitCondition( condition ); + + final int conditionChidrenHaveBooleans = conditionChidrenHaveBooleans( condition ); + + if ( conditionChidrenHaveBooleans > 0 ) + { + addViolation( condition, + ( conditionChidrenHaveBooleans == TRUE ? "" + : "!" ) + + "condition" ); + } + } + + private int conditionChidrenHaveBooleans( final IParserNode condition ) + { + if ( condition != null ) + { + for ( final IParserNode child : condition.getChildren() ) + { + if ( child.getStringValue() != null ) + { + if ( child.getStringValue().compareTo( "true" ) == 0 ) + { + return TRUE; + } + if ( child.getStringValue().compareTo( "false" ) == 0 ) + { + return FALSE; + } + } + } + } + return 0; + } +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e43b7a87/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/UselessOverridenFunctionRule.java ---------------------------------------------------------------------- diff --git a/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/UselessOverridenFunctionRule.java b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/UselessOverridenFunctionRule.java new file mode 100644 index 0000000..efcca82 --- /dev/null +++ b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/UselessOverridenFunctionRule.java @@ -0,0 +1,82 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.adobe.ac.pmd.rules.maintanability; + +import java.util.List; + +import com.adobe.ac.pmd.nodes.IFunction; +import com.adobe.ac.pmd.parser.IParserNode; +import com.adobe.ac.pmd.parser.KeyWords; +import com.adobe.ac.pmd.rules.core.AbstractAstFlexRule; +import com.adobe.ac.pmd.rules.core.ViolationPriority; + +/** + * @author xagnetti + */ +public class UselessOverridenFunctionRule extends AbstractAstFlexRule +{ + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#findViolations(com.adobe + * .ac.pmd.nodes.IFunction) + */ + @Override + protected final void findViolations( final IFunction function ) + { + final int statementNbAtFirstLevelInBody = function.getStatementNbInBody(); + + if ( function.getBody() != null + && function.isOverriden() && statementNbAtFirstLevelInBody == 1 ) + { + final List< IParserNode > statements = function.findPrimaryStatementsInBody( KeyWords.SUPER.toString() ); + + if ( statements != null + && statements.size() == 1 && function.getBody().getChild( 0 ).getChild( 1 ) != null + && function.getBody().getChild( 0 ).getChild( 1 ).getChild( 1 ) != null + && !areArgumentsModified( function.getBody().getChild( 0 ).getChild( 1 ).getChild( 1 ) ) ) + { + addViolation( function ); + } + } + } + + /* + * (non-Javadoc) + * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority() + */ + @Override + protected final ViolationPriority getDefaultPriority() + { + return ViolationPriority.LOW; + } + + private boolean areArgumentsModified( final IParserNode args ) + { + if ( args.getChildren() != null ) + { + for ( final IParserNode arg : args.getChildren() ) + { + if ( arg.getChildren() != null ) + { + return true; + } + } + } + return false; + } +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e43b7a87/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/forbiddentypes/AbstractUseForbiddenTypeRule.java ---------------------------------------------------------------------- diff --git a/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/forbiddentypes/AbstractUseForbiddenTypeRule.java b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/forbiddentypes/AbstractUseForbiddenTypeRule.java new file mode 100644 index 0000000..ca164e1 --- /dev/null +++ b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/forbiddentypes/AbstractUseForbiddenTypeRule.java @@ -0,0 +1,119 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.adobe.ac.pmd.rules.maintanability.forbiddentypes; + +import java.util.List; +import java.util.Map.Entry; + +import com.adobe.ac.pmd.nodes.IClass; +import com.adobe.ac.pmd.nodes.IFunction; +import com.adobe.ac.pmd.nodes.IVariable; +import com.adobe.ac.pmd.parser.IParserNode; +import com.adobe.ac.pmd.rules.core.AbstractAstFlexRule; + +/** + * @author xagnetti + */ +public abstract class AbstractUseForbiddenTypeRule extends AbstractAstFlexRule +{ + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#findViolations(com.adobe + * .ac.pmd.nodes.IClass) + */ + @Override + protected void findViolations( final IClass classNode ) + { + super.findViolations( classNode ); + + findViolationInVariableLists( classNode.getAttributes() ); + findViolationInVariableLists( classNode.getConstants() ); + } + + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#findViolations(com.adobe + * .ac.pmd.nodes.IFunction) + */ + @Override + protected void findViolations( final IFunction function ) + { + findViolationsInReturnType( function ); + if ( !function.isOverriden() ) + { + findViolationsInParametersList( function ); + } + findViolationsInLocalVariables( function ); + } + + /** + * @param function + */ + protected void findViolationsInParametersList( final IFunction function ) + { + findViolationInVariableLists( function.getParameters() ); + } + + /** + * @return + */ + protected abstract String getForbiddenType(); + + private < E extends IVariable > void findViolationInVariableLists( final List< E > variables ) + { + for ( final IVariable variable : variables ) + { + if ( variable.getType() != null ) + { + tryToAddViolation( variable.getInternalNode(), + variable.getType().toString() ); + } + } + } + + private void findViolationsInLocalVariables( final IFunction function ) + { + for ( final Entry< String, IParserNode > localVariableEntry : function.getLocalVariables().entrySet() ) + { + final IParserNode type = getTypeFromFieldDeclaration( localVariableEntry.getValue() ); + + tryToAddViolation( type, + type.getStringValue() ); + } + } + + private void findViolationsInReturnType( final IFunction function ) + { + if ( function != null + && function.getReturnType() != null ) + { + tryToAddViolation( function.getReturnType().getInternalNode(), + function.getReturnType().toString() ); + } + } + + private void tryToAddViolation( final IParserNode node, + final String typeName ) + { + if ( typeName.equals( getForbiddenType() ) ) + { + addViolation( node ); + } + } +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e43b7a87/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/forbiddentypes/UseDictionaryTypeRule.java ---------------------------------------------------------------------- diff --git a/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/forbiddentypes/UseDictionaryTypeRule.java b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/forbiddentypes/UseDictionaryTypeRule.java new file mode 100644 index 0000000..435e5a9 --- /dev/null +++ b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/forbiddentypes/UseDictionaryTypeRule.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.adobe.ac.pmd.rules.maintanability.forbiddentypes; + +import com.adobe.ac.pmd.rules.core.ViolationPriority; + +/** + * @author xagnetti + */ +public class UseDictionaryTypeRule extends AbstractUseForbiddenTypeRule // NO_UCD +{ + /* + * (non-Javadoc) + * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority() + */ + @Override + protected final ViolationPriority getDefaultPriority() + { + return ViolationPriority.HIGH; + } + + /* + * (non-Javadoc) + * @seecom.adobe.ac.pmd.rules.maintanability.forbiddentypes. + * AbstractUseForbiddenTypeRule#getForbiddenType() + */ + @Override + protected String getForbiddenType() + { + return "Dictionnary"; + } +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e43b7a87/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/forbiddentypes/UseGenericTypeRule.java ---------------------------------------------------------------------- diff --git a/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/forbiddentypes/UseGenericTypeRule.java b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/forbiddentypes/UseGenericTypeRule.java new file mode 100644 index 0000000..d6c6c08 --- /dev/null +++ b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/forbiddentypes/UseGenericTypeRule.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.adobe.ac.pmd.rules.maintanability.forbiddentypes; + +import com.adobe.ac.pmd.rules.core.ViolationPriority; + +/** + * @author xagnetti + */ +public class UseGenericTypeRule extends AbstractUseForbiddenTypeRule // NO_UCD +{ + private static final String STAR = "*"; + + /* + * (non-Javadoc) + * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority() + */ + @Override + protected final ViolationPriority getDefaultPriority() + { + return ViolationPriority.HIGH; + } + + /* + * (non-Javadoc) + * @seecom.adobe.ac.pmd.rules.maintanability.forbiddentypes. + * AbstractUseForbiddenTypeRule#getForbiddenType() + */ + @Override + protected String getForbiddenType() + { + return STAR; + } +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e43b7a87/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/forbiddentypes/UseObjectTypeRule.java ---------------------------------------------------------------------- diff --git a/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/forbiddentypes/UseObjectTypeRule.java b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/forbiddentypes/UseObjectTypeRule.java new file mode 100644 index 0000000..298ec98 --- /dev/null +++ b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/forbiddentypes/UseObjectTypeRule.java @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.adobe.ac.pmd.rules.maintanability.forbiddentypes; + +import com.adobe.ac.pmd.nodes.IClass; +import com.adobe.ac.pmd.nodes.IFunction; +import com.adobe.ac.pmd.parser.IParserNode; +import com.adobe.ac.pmd.rules.core.ViolationPriority; + +/** + * @author xagnetti + */ +public class UseObjectTypeRule extends AbstractUseForbiddenTypeRule // NO_UCD +{ + private boolean isResponder; + + /* + * (non-Javadoc) + * @seecom.adobe.ac.pmd.rules.maintanability.forbiddentypes. + * AbstractUseForbiddenTypeRule#findViolations(com.adobe.ac.pmd.nodes.IClass) + */ + @Override + protected void findViolations( final IClass classNode ) + { + for ( final IParserNode implementation : classNode.getImplementations() ) + { + if ( "IResponder".equals( implementation.getStringValue() ) ) + { + isResponder = true; + break; + } + } + + super.findViolations( classNode ); + } + + /* + * (non-Javadoc) + * @seecom.adobe.ac.pmd.rules.maintanability.forbiddentypes. + * AbstractUseForbiddenTypeRule + * #findViolationsInParametersList(com.adobe.ac.pmd.nodes.IFunction) + */ + @Override + protected void findViolationsInParametersList( final IFunction function ) + { + if ( !isResponderImplementation( function ) ) + { + super.findViolationsInParametersList( function ); + } + } + + /* + * (non-Javadoc) + * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority() + */ + @Override + protected final ViolationPriority getDefaultPriority() + { + return ViolationPriority.HIGH; + } + + /* + * (non-Javadoc) + * @seecom.adobe.ac.pmd.rules.maintanability.forbiddentypes. + * AbstractUseForbiddenTypeRule#getForbiddenType() + */ + @Override + protected String getForbiddenType() + { + return "Object"; + } + + private boolean isResponderImplementation( final IFunction function ) + { + return isResponder + && ( function.getName().equals( "result" ) || function.getName().equals( "fault" ) ); + } +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e43b7a87/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/multiscreen/AvoidRollMouseEventRule.java ---------------------------------------------------------------------- diff --git a/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/multiscreen/AvoidRollMouseEventRule.java b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/multiscreen/AvoidRollMouseEventRule.java new file mode 100644 index 0000000..1209086 --- /dev/null +++ b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/multiscreen/AvoidRollMouseEventRule.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.adobe.ac.pmd.rules.multiscreen; + +import com.adobe.ac.pmd.rules.core.AbstractRegexpBasedRule; +import com.adobe.ac.pmd.rules.core.ViolationPriority; + +/** + * @author xagnetti + */ +public class AvoidRollMouseEventRule extends AbstractRegexpBasedRule +{ + /* + * (non-Javadoc) + * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority() + */ + @Override + protected ViolationPriority getDefaultPriority() + { + return ViolationPriority.HIGH; + } + + /* + * (non-Javadoc) + * @see com.adobe.ac.pmd.rules.core.AbstractRegexpBasedRule#getRegexp() + */ + @Override + protected String getRegexp() + { + return ".*((mouseOut)|(MOUSE_OUT)|(mouseOver)|(MOUSE_OVER)|" + + "(rollOut)|(ROLL_OUT)|(rollOver)|(ROLL_OVER)).*"; + } + + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.core.AbstractFlexRule#isConcernedByTheCurrentFile() + */ + @Override + protected boolean isConcernedByTheCurrentFile() + { + return true; + } + + /* + * (non-Javadoc) + * @seecom.adobe.ac.pmd.rules.core.AbstractRegexpBasedRule# + * isViolationDetectedOnThisMatchingLine(java.lang.String) + */ + @Override + protected boolean isViolationDetectedOnThisMatchingLine( final String line ) + { + return true; + } +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e43b7a87/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/multiscreen/AvoidTooltipRule.java ---------------------------------------------------------------------- diff --git a/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/multiscreen/AvoidTooltipRule.java b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/multiscreen/AvoidTooltipRule.java new file mode 100644 index 0000000..ff3ed1f --- /dev/null +++ b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/multiscreen/AvoidTooltipRule.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.adobe.ac.pmd.rules.multiscreen; + +import com.adobe.ac.pmd.rules.core.AbstractRegexpBasedRule; +import com.adobe.ac.pmd.rules.core.ViolationPriority; + +/** + * @author xagnetti + */ +public class AvoidTooltipRule extends AbstractRegexpBasedRule +{ + /* + * (non-Javadoc) + * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority() + */ + @Override + protected ViolationPriority getDefaultPriority() + { + return ViolationPriority.HIGH; + } + + /* + * (non-Javadoc) + * @see com.adobe.ac.pmd.rules.core.AbstractRegexpBasedRule#getRegexp() + */ + @Override + protected String getRegexp() + { + return ".*\\s*toolTip\\s*=.*"; + } + + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.core.AbstractFlexRule#isConcernedByTheCurrentFile() + */ + @Override + protected boolean isConcernedByTheCurrentFile() + { + return true; + } + + /* + * (non-Javadoc) + * @seecom.adobe.ac.pmd.rules.core.AbstractRegexpBasedRule# + * isViolationDetectedOnThisMatchingLine(java.lang.String) + */ + @Override + protected boolean isViolationDetectedOnThisMatchingLine( final String line ) + { + return true; + } +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e43b7a87/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/mxml/AbstractMoreThanEntryPointInMxmlRule.java ---------------------------------------------------------------------- diff --git a/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/mxml/AbstractMoreThanEntryPointInMxmlRule.java b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/mxml/AbstractMoreThanEntryPointInMxmlRule.java new file mode 100644 index 0000000..fac8969 --- /dev/null +++ b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/mxml/AbstractMoreThanEntryPointInMxmlRule.java @@ -0,0 +1,110 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.adobe.ac.pmd.rules.mxml; + +import java.util.List; + +import com.adobe.ac.pmd.nodes.IAttribute; +import com.adobe.ac.pmd.nodes.IClass; +import com.adobe.ac.pmd.nodes.IFunction; +import com.adobe.ac.pmd.rules.core.AbstractAstFlexRule; +import com.adobe.ac.pmd.rules.core.ViolationPosition; + +/** + * @author xagnetti + */ +abstract class AbstractMoreThanEntryPointInMxmlRule extends AbstractAstFlexRule +{ + private int lastPublicVarLine = 0; + private int publicVarCount = 0; + + /** + * @return + */ + public abstract int getThreshold(); + + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#isConcernedByTheCurrentFile + * () + */ + @Override + public final boolean isConcernedByTheCurrentFile() + { + return getCurrentFile().isMxml(); + } + + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#findViolations(com.adobe + * .ac.pmd.nodes.IClass) + */ + @Override + protected void findViolations( final IClass classNode ) + { + publicVarCount = 0; + lastPublicVarLine = 0; + + super.findViolations( classNode ); + + if ( publicVarCount > getThreshold() ) + { + addViolation( ViolationPosition.create( lastPublicVarLine, + lastPublicVarLine, + 0, + getCurrentFile().getLineAt( lastPublicVarLine - 1 ).length() ) ); + } + } + + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#findViolations(com.adobe + * .ac.pmd.nodes.IFunction) + */ + @Override + protected final void findViolations( final IFunction function ) + { + if ( function.isPublic() + && function.isSetter() ) + { + publicVarCount++; + lastPublicVarLine = function.getInternalNode().getLine(); + } + } + + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#findViolationsFromAttributes + * (java.util.List) + */ + @Override + protected void findViolationsFromAttributes( final List< IAttribute > variables ) + { + for ( final IAttribute attribute : variables ) + { + if ( attribute.isPublic() ) + { + publicVarCount++; + lastPublicVarLine = attribute.getInternalNode().getLine(); + } + } + } +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e43b7a87/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/mxml/CodeBehindInMxmlRule.java ---------------------------------------------------------------------- diff --git a/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/mxml/CodeBehindInMxmlRule.java b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/mxml/CodeBehindInMxmlRule.java new file mode 100644 index 0000000..9e2bd13 --- /dev/null +++ b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/mxml/CodeBehindInMxmlRule.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.adobe.ac.pmd.rules.mxml; + +import com.adobe.ac.pmd.rules.core.AbstractRegexpBasedRule; +import com.adobe.ac.pmd.rules.core.ViolationPriority; + +/** + * @author xagnetti + */ +public class CodeBehindInMxmlRule extends AbstractRegexpBasedRule +{ + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.core.AbstractFlexRule#isConcernedByTheCurrentFile() + */ + @Override + public final boolean isConcernedByTheCurrentFile() + { + return getCurrentFile().isMxml(); + } + + /* + * (non-Javadoc) + * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority() + */ + @Override + protected final ViolationPriority getDefaultPriority() + { + return ViolationPriority.HIGH; + } + + /* + * (non-Javadoc) + * @see com.adobe.ac.pmd.rules.core.AbstractRegexpBasedRule#getRegexp() + */ + @Override + protected final String getRegexp() + { + return ".*<.*Script.*"; + } + + /* + * (non-Javadoc) + * @seecom.adobe.ac.pmd.rules.core.AbstractRegexpBasedRule# + * isViolationDetectedOnThisMatchingLine(java.lang.String) + */ + @Override + protected final boolean isViolationDetectedOnThisMatchingLine( final String line ) + { + return line.contains( "source" ); + } +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e43b7a87/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/mxml/MoreThanOneEntryPointInMxmlRule.java ---------------------------------------------------------------------- diff --git a/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/mxml/MoreThanOneEntryPointInMxmlRule.java b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/mxml/MoreThanOneEntryPointInMxmlRule.java new file mode 100644 index 0000000..c28758b --- /dev/null +++ b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/mxml/MoreThanOneEntryPointInMxmlRule.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.adobe.ac.pmd.rules.mxml; + +import com.adobe.ac.pmd.rules.core.ViolationPriority; + +/** + * @author xagnetti + */ +public class MoreThanOneEntryPointInMxmlRule extends AbstractMoreThanEntryPointInMxmlRule +{ + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.mxml.AbstractMoreThanEntryPointInMxmlRule#getThreshold + * () + */ + @Override + public final int getThreshold() + { + return 1; + } + + /* + * (non-Javadoc) + * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority() + */ + @Override + protected final ViolationPriority getDefaultPriority() + { + return ViolationPriority.LOW; + } +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e43b7a87/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/mxml/MoreThanTwoEntryPointsInMxmlRule.java ---------------------------------------------------------------------- diff --git a/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/mxml/MoreThanTwoEntryPointsInMxmlRule.java b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/mxml/MoreThanTwoEntryPointsInMxmlRule.java new file mode 100644 index 0000000..7f768a4 --- /dev/null +++ b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/mxml/MoreThanTwoEntryPointsInMxmlRule.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.adobe.ac.pmd.rules.mxml; + +import com.adobe.ac.pmd.rules.core.ViolationPriority; + +/** + * @author xagnetti + */ +public class MoreThanTwoEntryPointsInMxmlRule extends AbstractMoreThanEntryPointInMxmlRule +{ + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.mxml.AbstractMoreThanEntryPointInMxmlRule#getThreshold + * () + */ + @Override + public final int getThreshold() + { + return 2; + } + + /* + * (non-Javadoc) + * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority() + */ + @Override + protected final ViolationPriority getDefaultPriority() + { + return ViolationPriority.NORMAL; + } +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e43b7a87/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/mxml/OnlyOneScriptBlockPerMxmlRule.java ---------------------------------------------------------------------- diff --git a/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/mxml/OnlyOneScriptBlockPerMxmlRule.java b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/mxml/OnlyOneScriptBlockPerMxmlRule.java new file mode 100644 index 0000000..2041b13 --- /dev/null +++ b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/mxml/OnlyOneScriptBlockPerMxmlRule.java @@ -0,0 +1,97 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.adobe.ac.pmd.rules.mxml; + +import java.util.List; + +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpressionException; + +import org.w3c.dom.Document; + +import com.adobe.ac.pmd.IFlexViolation; +import com.adobe.ac.pmd.rules.core.AbstractXpathRelatedRule; +import com.adobe.ac.pmd.rules.core.ViolationPosition; +import com.adobe.ac.pmd.rules.core.ViolationPriority; + +/** + * @author xagnetti + */ +public class OnlyOneScriptBlockPerMxmlRule extends AbstractXpathRelatedRule +{ + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.core.AbstractXpathRelatedRule#evaluate(org.w3c. + * dom.Document, javax.xml.xpath.XPath) + */ + @Override + protected Object evaluate( final Document doc, + final XPath xPath ) throws XPathExpressionException + { + return xPath.evaluate( getXPathExpression(), + doc, + XPathConstants.NUMBER ); + } + + /* + * (non-Javadoc) + * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority() + */ + @Override + protected ViolationPriority getDefaultPriority() + { + return ViolationPriority.HIGH; + } + + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.core.AbstractXpathRelatedRule#getXPathExpression() + */ + @Override + protected String getXPathExpression() + { + return "count(//mx:Script)"; + } + + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.core.AbstractXpathRelatedRule#onEvaluated(java. + * util.List, org.w3c.dom.Document, javax.xml.xpath.XPath) + */ + @Override + protected void onEvaluated( final List< IFlexViolation > violations, + final Document doc, + final XPath xPath ) throws XPathExpressionException + { + final Double scriptNb = ( Double ) evaluate( doc, + xPath ); + + if ( scriptNb >= 2 ) + { + addViolation( violations, + ViolationPosition.create( 1, + 1, + 0, + 0 ), + String.valueOf( scriptNb ) ); + } + } +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e43b7a87/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/mxml/StaticMethodInMxmlRule.java ---------------------------------------------------------------------- diff --git a/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/mxml/StaticMethodInMxmlRule.java b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/mxml/StaticMethodInMxmlRule.java new file mode 100644 index 0000000..2aaf314 --- /dev/null +++ b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/mxml/StaticMethodInMxmlRule.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.adobe.ac.pmd.rules.mxml; + +import com.adobe.ac.pmd.nodes.IFunction; +import com.adobe.ac.pmd.nodes.Modifier; +import com.adobe.ac.pmd.rules.core.AbstractAstFlexRule; +import com.adobe.ac.pmd.rules.core.ViolationPriority; + +/** + * @author xagnetti + */ +public class StaticMethodInMxmlRule extends AbstractAstFlexRule +{ + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#isConcernedByTheCurrentFile + * () + */ + @Override + public final boolean isConcernedByTheCurrentFile() + { + return getCurrentFile().isMxml(); + } + + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#findViolations(com.adobe + * .ac.pmd.nodes.IFunction) + */ + @Override + protected final void findViolations( final IFunction function ) + { + if ( function.is( Modifier.STATIC ) ) + { + addViolation( function ); + } + } + + /* + * (non-Javadoc) + * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority() + */ + @Override + protected final ViolationPriority getDefaultPriority() + { + return ViolationPriority.LOW; + } + +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e43b7a87/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/mxml/TooLongScriptBlockRule.java ---------------------------------------------------------------------- diff --git a/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/mxml/TooLongScriptBlockRule.java b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/mxml/TooLongScriptBlockRule.java new file mode 100644 index 0000000..4e54d8c --- /dev/null +++ b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/mxml/TooLongScriptBlockRule.java @@ -0,0 +1,99 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.adobe.ac.pmd.rules.mxml; + +import java.util.ArrayList; +import java.util.List; + +import com.adobe.ac.pmd.IFlexViolation; +import com.adobe.ac.pmd.files.IMxmlFile; +import com.adobe.ac.pmd.rules.core.ViolationPosition; +import com.adobe.ac.pmd.rules.core.ViolationPriority; +import com.adobe.ac.pmd.rules.core.thresholded.AbstractMaximizedFlexRule; + +/** + * @author xagnetti + */ +public class TooLongScriptBlockRule extends AbstractMaximizedFlexRule +{ + public static final int DEFAULT_THRESHOLD = 50; + private int linesInScriptBlock; + + /* + * (non-Javadoc) + * @seecom.adobe.ac.pmd.rules.core.thresholded.IThresholdedRule# + * getActualValueForTheCurrentViolation() + */ + public final int getActualValueForTheCurrentViolation() + { + return linesInScriptBlock; + } + + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.core.thresholded.IThresholdedRule#getDefaultThreshold + * () + */ + public final int getDefaultThreshold() + { + return DEFAULT_THRESHOLD; + } + + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.core.AbstractFlexRule#isConcernedByTheCurrentFile() + */ + @Override + public final boolean isConcernedByTheCurrentFile() + { + return getCurrentFile().isMxml(); + } + + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.core.AbstractFlexRule#findViolationsInCurrentFile() + */ + @Override + protected final List< IFlexViolation > findViolationsInCurrentFile() + { + final List< IFlexViolation > violations = new ArrayList< IFlexViolation >(); + final IMxmlFile mxml = ( IMxmlFile ) getCurrentFile(); + + linesInScriptBlock = mxml.getEndingScriptBlock() + - mxml.getBeginningScriptBlock(); + + if ( linesInScriptBlock >= getThreshold() ) + { + addViolation( violations, + new ViolationPosition( mxml.getBeginningScriptBlock(), mxml.getEndingScriptBlock() ) ); + } + return violations; + } + + /* + * (non-Javadoc) + * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority() + */ + @Override + protected final ViolationPriority getDefaultPriority() + { + return ViolationPriority.NORMAL; + } +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e43b7a87/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/mxml/TooManyStatesInMxmlRule.java ---------------------------------------------------------------------- diff --git a/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/mxml/TooManyStatesInMxmlRule.java b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/mxml/TooManyStatesInMxmlRule.java new file mode 100644 index 0000000..d0ac6c5 --- /dev/null +++ b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/mxml/TooManyStatesInMxmlRule.java @@ -0,0 +1,159 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.adobe.ac.pmd.rules.mxml; + +import java.util.List; +import java.util.Map; + +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpressionException; + +import net.sourceforge.pmd.PropertyDescriptor; + +import org.w3c.dom.Document; + +import com.adobe.ac.pmd.IFlexViolation; +import com.adobe.ac.pmd.rules.core.AbstractXpathRelatedRule; +import com.adobe.ac.pmd.rules.core.ViolationPosition; +import com.adobe.ac.pmd.rules.core.ViolationPriority; +import com.adobe.ac.pmd.rules.core.thresholded.IThresholdedRule; + +/** + * @author xagnetti + */ +public class TooManyStatesInMxmlRule extends AbstractXpathRelatedRule implements IThresholdedRule +{ + private Double statesNb = 0.0; + + /* + * (non-Javadoc) + * @seecom.adobe.ac.pmd.rules.core.thresholded.IThresholdedRule# + * getActualValueForTheCurrentViolation() + */ + public int getActualValueForTheCurrentViolation() + { + return statesNb.intValue(); + } + + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.core.thresholded.IThresholdedRule#getDefaultThreshold + * () + */ + public int getDefaultThreshold() + { + return 5; + } + + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.core.thresholded.IThresholdedRule#getThreshold() + */ + public int getThreshold() + { + return getIntProperty( propertyDescriptorFor( getThresholdName() ) ); + } + + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.core.thresholded.IThresholdedRule#getThresholdName + * () + */ + public final String getThresholdName() + { + return MAXIMUM; + } + + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.core.AbstractXpathRelatedRule#evaluate(org.w3c. + * dom.Document, javax.xml.xpath.XPath) + */ + @Override + protected Object evaluate( final Document doc, + final XPath xPath ) throws XPathExpressionException + { + return xPath.evaluate( getXPathExpression(), + doc, + XPathConstants.NUMBER ); + } + + /* + * (non-Javadoc) + * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority() + */ + @Override + protected ViolationPriority getDefaultPriority() + { + return ViolationPriority.NORMAL; + } + + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.core.AbstractXpathRelatedRule#getXPathExpression() + */ + @Override + protected String getXPathExpression() + { + return "count(//mx:states/*)"; + } + + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.core.AbstractXpathRelatedRule#onEvaluated(java. + * util.List, org.w3c.dom.Document, javax.xml.xpath.XPath) + */ + @Override + protected void onEvaluated( final List< IFlexViolation > violations, + final Document doc, + final XPath xPath ) throws XPathExpressionException + { + statesNb = ( Double ) evaluate( doc, + xPath ); + + if ( statesNb >= getThreshold() ) + { + xPath.evaluate( "//mx:states/*", + doc, + XPathConstants.NODESET ); + + addViolation( violations, + ViolationPosition.create( 1, + 1, + 0, + 0 ), + String.valueOf( getActualValueForTheCurrentViolation() ) ); + } + } + + /* + * (non-Javadoc) + * @see net.sourceforge.pmd.CommonAbstractRule#propertiesByName() + */ + @Override + protected final Map< String, PropertyDescriptor > propertiesByName() + { + return getThresholdedRuleProperties( this ); + } +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e43b7a87/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/naming/BooleanAttributeShouldContainIsHasRule.java ---------------------------------------------------------------------- diff --git a/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/naming/BooleanAttributeShouldContainIsHasRule.java b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/naming/BooleanAttributeShouldContainIsHasRule.java new file mode 100644 index 0000000..1f33580 --- /dev/null +++ b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/naming/BooleanAttributeShouldContainIsHasRule.java @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.adobe.ac.pmd.rules.naming; + +import java.util.List; + +import com.adobe.ac.pmd.nodes.IAttribute; +import com.adobe.ac.pmd.nodes.IFunction; +import com.adobe.ac.pmd.nodes.INamableNode; +import com.adobe.ac.pmd.rules.core.AbstractAstFlexRule; +import com.adobe.ac.pmd.rules.core.ViolationPriority; + +public class BooleanAttributeShouldContainIsHasRule extends AbstractAstFlexRule +{ + private static final String BOOLEAN = "Boolean"; + private static final String[] FORBIDDEN_NAMES = new String[] + { "has", + "is", + "can" }; + + @Override + protected void findViolations( final IFunction function ) + { + if ( function.isGetter() + && function.isPublic() && function.getReturnType().toString().compareTo( BOOLEAN ) == 0 ) + { + isWronglyNamed( function ); + } + } + + @Override + protected void findViolationsFromAttributes( final List< IAttribute > variables ) + { + for ( final IAttribute variable : variables ) + { + if ( variable.getName().compareTo( BOOLEAN ) == 0 ) + { + isWronglyNamed( variable ); + } + } + } + + @Override + protected ViolationPriority getDefaultPriority() + { + return ViolationPriority.LOW; + } + + private void isWronglyNamed( final INamableNode namable ) + { + for ( final String forbiddenName : FORBIDDEN_NAMES ) + { + if ( namable.getName().startsWith( forbiddenName ) ) + { + return; + } + } + addViolation( namable, + namable.getName() ); + } +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e43b7a87/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/naming/CapitalizeConstantsRule.java ---------------------------------------------------------------------- diff --git a/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/naming/CapitalizeConstantsRule.java b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/naming/CapitalizeConstantsRule.java new file mode 100644 index 0000000..ae57015 --- /dev/null +++ b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/naming/CapitalizeConstantsRule.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.adobe.ac.pmd.rules.naming; + +import java.util.List; +import java.util.Locale; + +import com.adobe.ac.pmd.nodes.IConstant; +import com.adobe.ac.pmd.rules.core.AbstractAstFlexRule; +import com.adobe.ac.pmd.rules.core.ViolationPriority; + +public class CapitalizeConstantsRule extends AbstractAstFlexRule +{ + @Override + protected void findViolationsFromConstants( final List< IConstant > constants ) + { + for ( final IConstant constant : constants ) + { + if ( nameContainsLowerCase( constant.getName() ) ) + { + addViolation( constant, + constant.getName() ); + } + } + } + + @Override + protected ViolationPriority getDefaultPriority() + { + return ViolationPriority.NORMAL; + } + + private boolean nameContainsLowerCase( final String name ) + { + return name.toUpperCase( Locale.getDefault() ).compareTo( name ) != 0; + } +}