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/style/ImportFromSamePackageRule.java ---------------------------------------------------------------------- diff --git a/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/style/ImportFromSamePackageRule.java b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/style/ImportFromSamePackageRule.java new file mode 100644 index 0000000..ef71b6d --- /dev/null +++ b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/style/ImportFromSamePackageRule.java @@ -0,0 +1,61 @@ +/* + * 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.style; + +import org.apache.commons.lang.StringUtils; + +import com.adobe.ac.pmd.nodes.IPackage; +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 ImportFromSamePackageRule extends AbstractAstFlexRule +{ + /* + * (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 ) + { + final String packageName = packageNode.getName(); + + for ( final IParserNode importNode : packageNode.getImports() ) + { + if ( StringUtils.substringBeforeLast( importNode.toString(), + "." ).equals( packageName ) ) + { + addViolation( importNode ); + } + } + } + + /* + * (non-Javadoc) + * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority() + */ + @Override + protected final ViolationPriority getDefaultPriority() + { + return ViolationPriority.LOW; + } +} \ No newline at end of file
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/style/OverLongLineRule.java ---------------------------------------------------------------------- diff --git a/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/style/OverLongLineRule.java b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/style/OverLongLineRule.java new file mode 100644 index 0000000..1e80663 --- /dev/null +++ b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/style/OverLongLineRule.java @@ -0,0 +1,114 @@ +/* + * 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.style; + +import java.util.ArrayList; +import java.util.List; + +import com.adobe.ac.pmd.IFlexViolation; +import com.adobe.ac.pmd.files.IFlexFile; +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 OverLongLineRule extends AbstractMaximizedFlexRule +{ + private static final int DEFAULT_THRESHOLD = 120; + private int currentLineLength; + + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.core.AbstractFlexRule#findViolationsInCurrentFile() + */ + @Override + public final List< IFlexViolation > findViolationsInCurrentFile() + { + final List< IFlexViolation > violations = new ArrayList< IFlexViolation >(); + + if ( isConcernedByTheCurrentFile() ) + { + final IFlexFile currentFile = getCurrentFile(); + + for ( int i = 1; i <= currentFile.getLinesNb(); i++ ) + { + final String line = currentFile.getLineAt( i ); + + if ( !line.trim().startsWith( "import" ) + && line.length() > getThreshold() ) + { + currentLineLength = line.length(); + final ViolationPosition position = ViolationPosition.create( i, + i, + 0, + currentLineLength ); + + addViolation( violations, + position ); + } + } + } + return violations; + } + + /* + * (non-Javadoc) + * @seecom.adobe.ac.pmd.rules.core.thresholded.IThresholdedRule# + * getActualValueForTheCurrentViolation() + */ + @Override + public final int getActualValueForTheCurrentViolation() + { + return currentLineLength; + } + + /* + * (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.AbstractFlexRule#getDefaultPriority() + */ + @Override + protected final ViolationPriority getDefaultPriority() + { + return ViolationPriority.LOW; + } + + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.core.AbstractFlexRule#isConcernedByTheCurrentFile() + */ + @Override + protected boolean isConcernedByTheCurrentFile() + { + 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/style/TabUsedAsIndentorRule.java ---------------------------------------------------------------------- diff --git a/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/style/TabUsedAsIndentorRule.java b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/style/TabUsedAsIndentorRule.java new file mode 100644 index 0000000..37f44a3 --- /dev/null +++ b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/style/TabUsedAsIndentorRule.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.style; + +import com.adobe.ac.pmd.rules.core.AbstractRegexpBasedRule; +import com.adobe.ac.pmd.rules.core.ViolationPriority; + +public class TabUsedAsIndentorRule extends AbstractRegexpBasedRule +{ + + @Override + protected ViolationPriority getDefaultPriority() + { + return ViolationPriority.NORMAL; + } + + @Override + protected String getRegexp() + { + return "^ *\t.*"; + } + + @Override + protected boolean isConcernedByTheCurrentFile() + { + return !getCurrentFile().isMxml(); + } + + @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/switchrules/IdenticalSwitchCasesRule.java ---------------------------------------------------------------------- diff --git a/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/switchrules/IdenticalSwitchCasesRule.java b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/switchrules/IdenticalSwitchCasesRule.java new file mode 100644 index 0000000..fad7a45 --- /dev/null +++ b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/switchrules/IdenticalSwitchCasesRule.java @@ -0,0 +1,73 @@ +/* + * 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.switchrules; + +import java.util.LinkedHashMap; +import java.util.Map; + +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 IdenticalSwitchCasesRule extends AbstractAstFlexRule +{ + /* + * (non-Javadoc) + * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority() + */ + @Override + protected final ViolationPriority getDefaultPriority() + { + return ViolationPriority.LOW; + } + + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#visitSwitch(com.adobe. + * ac.pmd.parser.IParserNode) + */ + @Override + protected final void visitSwitch( final IParserNode ast ) + { + super.visitSwitch( ast ); + + if ( ast.numChildren() > 0 ) + { + final Map< String, IParserNode > cases = new LinkedHashMap< String, IParserNode >(); + + for ( final IParserNode caseStatement : ast.getChild( 1 ).getChildren() ) + { + final String label = caseStatement.getChild( 0 ).toString(); + + if ( cases.containsKey( label ) ) + { + addViolation( caseStatement ); + break; + } + else + { + cases.put( label, + caseStatement ); + } + } + } + } +} 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/switchrules/NestedSwitchRule.java ---------------------------------------------------------------------- diff --git a/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/switchrules/NestedSwitchRule.java b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/switchrules/NestedSwitchRule.java new file mode 100644 index 0000000..38dd7e5 --- /dev/null +++ b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/switchrules/NestedSwitchRule.java @@ -0,0 +1,58 @@ +/* + * 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.switchrules; + +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 NestedSwitchRule extends AbstractAstFlexRule +{ + private int switchLevel = 0; + + /* + * (non-Javadoc) + * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority() + */ + @Override + protected final ViolationPriority getDefaultPriority() + { + return ViolationPriority.NORMAL; + } + + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#visitSwitch(com.adobe. + * ac.pmd.parser.IParserNode) + */ + @Override + protected final void visitSwitch( final IParserNode ast ) + { + switchLevel++; + if ( switchLevel > 1 ) + { + addViolation( ast ); + } + super.visitSwitch( ast ); + + switchLevel--; + } +} 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/switchrules/NonBreakableSwitchCaseRule.java ---------------------------------------------------------------------- diff --git a/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/switchrules/NonBreakableSwitchCaseRule.java b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/switchrules/NonBreakableSwitchCaseRule.java new file mode 100644 index 0000000..3697903 --- /dev/null +++ b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/switchrules/NonBreakableSwitchCaseRule.java @@ -0,0 +1,41 @@ +/* + * 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.switchrules; + +import com.adobe.ac.pmd.parser.IParserNode; +import com.adobe.ac.pmd.rules.core.AbstractAstFlexRule; +import com.adobe.ac.pmd.rules.core.ViolationPriority; + +public class NonBreakableSwitchCaseRule extends AbstractAstFlexRule +{ + @Override + protected ViolationPriority getDefaultPriority() + { + return ViolationPriority.HIGH; + } + + @Override + protected void visitSwitchCase( final IParserNode switchCaseNode ) + { + if ( switchCaseNode.getChildren() != null + && switchCaseNode.getChildren().size() > 0 + && switchCaseNode.getLastChild().getStringValue().compareTo( "break" ) != 0 ) + { + addViolation( switchCaseNode ); + } + } +} 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/switchrules/SwitchStatementsShouldHaveDefaultRule.java ---------------------------------------------------------------------- diff --git a/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/switchrules/SwitchStatementsShouldHaveDefaultRule.java b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/switchrules/SwitchStatementsShouldHaveDefaultRule.java new file mode 100644 index 0000000..163333e --- /dev/null +++ b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/switchrules/SwitchStatementsShouldHaveDefaultRule.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.switchrules; + +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 SwitchStatementsShouldHaveDefaultRule extends AbstractAstFlexRule +{ + private boolean defaultStatementFound = false; + + /* + * (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.AbstractAstFlexRule#visitSwitch(com.adobe. + * ac.pmd.parser.IParserNode) + */ + @Override + protected final void visitSwitch( final IParserNode ast ) + { + super.visitSwitch( ast ); + + if ( !defaultStatementFound ) + { + ast.getChild( 1 ); + + addViolation( ast ); + } + } + + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#visitSwitchDefaultCase + * (com.adobe.ac.pmd.parser.IParserNode) + */ + @Override + protected final void visitSwitchDefaultCase( final IParserNode child ) + { + super.visitSwitchDefaultCase( child ); + + if ( child.numChildren() != 0 ) + { + defaultStatementFound = 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/switchrules/TooFewBrancheInSwitchStatementRule.java ---------------------------------------------------------------------- diff --git a/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/switchrules/TooFewBrancheInSwitchStatementRule.java b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/switchrules/TooFewBrancheInSwitchStatementRule.java new file mode 100644 index 0000000..2f4aae9 --- /dev/null +++ b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/switchrules/TooFewBrancheInSwitchStatementRule.java @@ -0,0 +1,144 @@ +/* + * 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.switchrules; + +import java.util.Map; + +import net.sourceforge.pmd.PropertyDescriptor; + +import com.adobe.ac.pmd.parser.IParserNode; +import com.adobe.ac.pmd.rules.core.AbstractAstFlexRule; +import com.adobe.ac.pmd.rules.core.ViolationPriority; +import com.adobe.ac.pmd.rules.core.thresholded.IThresholdedRule; + +/** + * @author xagnetti + */ +public class TooFewBrancheInSwitchStatementRule extends AbstractAstFlexRule implements IThresholdedRule +{ + public static final int DEFAULT_THRESHOLD = 3; + private int switchCases; + + /* + * (non-Javadoc) + * @seecom.adobe.ac.pmd.rules.core.thresholded.IThresholdedRule# + * getActualValueForTheCurrentViolation() + */ + public final int getActualValueForTheCurrentViolation() + { + return switchCases; + } + + /* + * (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.thresholded.IThresholdedRule#getThreshold() + */ + public final int getThreshold() + { + return getIntProperty( propertyDescriptorFor( getThresholdName() ) ); + } + + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.core.thresholded.IThresholdedRule#getThresholdName + * () + */ + public final String getThresholdName() + { + return MINIMUM; + } + + /* + * (non-Javadoc) + * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority() + */ + @Override + protected final ViolationPriority getDefaultPriority() + { + return ViolationPriority.LOW; + } + + /* + * (non-Javadoc) + * @see net.sourceforge.pmd.CommonAbstractRule#propertiesByName() + */ + @Override + protected final Map< String, PropertyDescriptor > propertiesByName() + { + return getThresholdedRuleProperties( this ); + } + + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#visitSwitch(com.adobe. + * ac.pmd.parser.IParserNode) + */ + @Override + protected final void visitSwitch( final IParserNode ast ) + { + switchCases = 0; + + super.visitSwitch( ast ); + + if ( switchCases < getThreshold() ) + { + addViolation( ast ); + } + } + + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#visitSwitchCase(com.adobe + * .ac.pmd.parser.IParserNode) + */ + @Override + protected final void visitSwitchCase( final IParserNode child ) + { + super.visitSwitchCase( child ); + + switchCases++; + } + + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#visitSwitchDefaultCase + * (com.adobe.ac.pmd.parser.IParserNode) + */ + @Override + protected void visitSwitchDefaultCase( final IParserNode defaultCaseNode ) + { + super.visitSwitchDefaultCase( defaultCaseNode ); + + switchCases++; + } +} 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/unused/AbstractUnusedVariableRule.java ---------------------------------------------------------------------- diff --git a/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/unused/AbstractUnusedVariableRule.java b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/unused/AbstractUnusedVariableRule.java new file mode 100644 index 0000000..63640b2 --- /dev/null +++ b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/unused/AbstractUnusedVariableRule.java @@ -0,0 +1,130 @@ +/* + * 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.unused; + +import java.util.Map; + +import com.adobe.ac.pmd.parser.IParserNode; +import com.adobe.ac.pmd.parser.NodeKind; +import com.adobe.ac.pmd.rules.core.AbstractAstFlexRule; + +/** + * @author xagnetti + */ +abstract class AbstractUnusedVariableRule extends AbstractAstFlexRule +{ + private Map< String, IParserNode > variablesUnused; + + /** + * @param variableName + * @param ast + */ + protected final void addVariable( final String variableName, + final IParserNode ast ) + { + variablesUnused.put( variableName, + ast ); + } + + /** + * @return + */ + protected Map< String, IParserNode > getVariablesUnused() + { + return variablesUnused; + } + + /** + * @param variablesUnusedToBeSet + */ + protected void setVariablesUnused( final Map< String, IParserNode > variablesUnusedToBeSet ) + { + variablesUnused = variablesUnusedToBeSet; + } + + /** + * @param ast + */ + protected final void tryToAddVariableNodeInChildren( final IParserNode ast ) + { + if ( ast != null + && !tryToAddVariableNode( ast ) && ast.is( NodeKind.VAR_LIST ) ) + { + for ( final IParserNode child : ast.getChildren() ) + { + tryToAddVariableNode( child ); + } + } + } + + /** + * @param ast + */ + protected final void tryToMarkVariableAsUsed( final IParserNode ast ) + { + if ( variablesUnused != null + && ast != null ) + { + markVariableAsUsed( ast ); + } + } + + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#visitStatement(com.adobe + * .ac.pmd.parser.IParserNode) + */ + @Override + protected void visitStatement( final IParserNode ast ) + { + super.visitStatement( ast ); + + tryToMarkVariableAsUsed( ast ); + } + + private void markVariableAsUsed( final IParserNode ast ) + { + if ( ast.numChildren() == 0 ) + { + if ( variablesUnused.containsKey( ast.getStringValue() ) ) + { + variablesUnused.remove( ast.getStringValue() ); + } + } + else + { + for ( final IParserNode child : ast.getChildren() ) + { + markVariableAsUsed( child ); + } + } + } + + private boolean tryToAddVariableNode( final IParserNode ast ) + { + boolean result = false; + + if ( ast.is( NodeKind.NAME_TYPE_INIT ) ) + { + addVariable( ast.getChild( 0 ).getStringValue(), + ast ); + result = true; + } + return result; + } +} 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/unused/EmptyPrivateMethodRule.java ---------------------------------------------------------------------- diff --git a/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/unused/EmptyPrivateMethodRule.java b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/unused/EmptyPrivateMethodRule.java new file mode 100644 index 0000000..f9805c1 --- /dev/null +++ b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/unused/EmptyPrivateMethodRule.java @@ -0,0 +1,41 @@ +/* + * 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.unused; + +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; + +public class EmptyPrivateMethodRule extends AbstractAstFlexRule +{ + @Override + protected final void findViolations( final IFunction function ) + { + if ( function.is( Modifier.PRIVATE ) + && function.getBody().numChildren() == 0 ) + { + addViolation( function ); + } + } + + @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/unused/UnusedFieldRule.java ---------------------------------------------------------------------- diff --git a/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/unused/UnusedFieldRule.java b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/unused/UnusedFieldRule.java new file mode 100644 index 0000000..c6bc6fd --- /dev/null +++ b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/unused/UnusedFieldRule.java @@ -0,0 +1,128 @@ +/* + * 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.unused; + +import java.util.LinkedHashMap; +import java.util.List; + +import com.adobe.ac.pmd.parser.IParserNode; +import com.adobe.ac.pmd.parser.KeyWords; +import com.adobe.ac.pmd.rules.core.ViolationPriority; + +/** + * @author xagnetti + */ +public class UnusedFieldRule extends AbstractUnusedVariableRule +{ + /* + * (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.AbstractFlexRule#getDefaultPriority() + */ + @Override + protected final ViolationPriority getDefaultPriority() + { + return ViolationPriority.HIGH; + } + + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#visitClass(com.adobe.ac + * .pmd.parser.IParserNode) + */ + @Override + protected final void visitClass( final IParserNode classNode ) + { + setVariablesUnused( new LinkedHashMap< String, IParserNode >() ); + + super.visitClass( classNode ); + + for ( final String variableName : getVariablesUnused().keySet() ) + { + final IParserNode variable = getVariablesUnused().get( variableName ); + + addViolation( variable, + variable, + variableName ); + } + } + + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#visitVariableInitialization + * (com.adobe.ac.pmd.parser.IParserNode) + */ + @Override + protected final void visitVariableInitialization( final IParserNode node ) + { + super.visitVariableInitialization( node ); + + tryToMarkVariableAsUsed( node ); + } + + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#visitVarOrConstList(com + * .adobe.ac.pmd.parser.IParserNode, + * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule.VariableOrConstant, + * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule.VariableScope) + */ + @Override + protected final void visitVarOrConstList( final IParserNode ast, + final VariableOrConstant varOrConst, + final VariableScope scope ) + { + if ( scope.equals( VariableScope.IN_CLASS ) ) + { + final List< IParserNode > modifiers = ast.getChild( 0 ).getChildren(); + boolean isPrivate = false; + + if ( !modifiers.isEmpty() ) + { + for ( final IParserNode modifierNode : modifiers ) + { + if ( modifierNode.getStringValue().equals( KeyWords.PRIVATE.toString() ) ) + { + isPrivate = true; + break; + } + } + } + if ( isPrivate ) + { + tryToAddVariableNodeInChildren( ast ); + } + } + super.visitVarOrConstList( ast, + varOrConst, + scope ); + } +} 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/unused/UnusedLocalVariableRule.java ---------------------------------------------------------------------- diff --git a/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/unused/UnusedLocalVariableRule.java b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/unused/UnusedLocalVariableRule.java new file mode 100644 index 0000000..64df71a --- /dev/null +++ b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/unused/UnusedLocalVariableRule.java @@ -0,0 +1,76 @@ +/* + * 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.unused; + +import java.util.LinkedHashMap; + +import com.adobe.ac.pmd.parser.IParserNode; +import com.adobe.ac.pmd.rules.core.ViolationPriority; + +/** + * @author xagnetti + */ +public class UnusedLocalVariableRule extends AbstractUnusedVariableRule +{ + /* + * (non-Javadoc) + * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority() + */ + @Override + protected final 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 final void visitFunction( final IParserNode ast, + final FunctionType type ) + { + setVariablesUnused( new LinkedHashMap< String, IParserNode >() ); + + super.visitFunction( ast, + type ); + for ( final String variableName : getVariablesUnused().keySet() ) + { + final IParserNode variable = getVariablesUnused().get( variableName ); + + addViolation( variable, + variable, + variableName ); + } + } + + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.unused.AbstractUnusedVariableRule#visitStatement + * (com.adobe.ac.pmd.parser.IParserNode) + */ + @Override + protected final void visitStatement( final IParserNode ast ) + { + super.visitStatement( ast ); + tryToAddVariableNodeInChildren( 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/unused/UnusedParameterRule.java ---------------------------------------------------------------------- diff --git a/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/unused/UnusedParameterRule.java b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/unused/UnusedParameterRule.java new file mode 100644 index 0000000..305def5 --- /dev/null +++ b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/unused/UnusedParameterRule.java @@ -0,0 +1,239 @@ +/* + * 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.unused; + +import java.util.LinkedHashMap; + +import com.adobe.ac.pmd.parser.IParserNode; +import com.adobe.ac.pmd.parser.KeyWords; +import com.adobe.ac.pmd.parser.NodeKind; +import com.adobe.ac.pmd.rules.core.ViolationPriority; +import com.adobe.ac.pmd.rules.parsley.utils.ParsleyMetaData; +import com.adobe.ac.pmd.rules.parsley.utils.MetaDataTag.Location; + +/** + * @author xagnetti + */ +public class UnusedParameterRule extends AbstractUnusedVariableRule +{ + private static final String DATA_GRID_COLUMN = "DataGridColumn"; + private static final String FAULT_FUNCTION_NAME = "fault"; + private static final String RESPONDER_INTERFACE_NAME = "Responder"; + private static final String RESULT_FUNCTION_NAME = "result"; + + private static String computeFunctionName( final IParserNode functionAst ) + { + String functionName = ""; + for ( final IParserNode node : functionAst.getChildren() ) + { + if ( node.is( NodeKind.NAME ) ) + { + functionName = node.getStringValue(); + break; + } + } + return functionName; + } + + private static boolean isClassImplementingIResponder( final IParserNode currentClass2 ) + { + for ( final IParserNode node : currentClass2.getChildren() ) + { + if ( node.is( NodeKind.IMPLEMENTS_LIST ) ) + { + for ( final IParserNode implementation : node.getChildren() ) + { + if ( implementation.getStringValue() != null + && implementation.getStringValue().contains( RESPONDER_INTERFACE_NAME ) ) + { + return true; + } + } + } + } + return false; + } + + private static boolean isResponderImplementation( final IParserNode currentClass, + final IParserNode functionAst ) + { + if ( !isClassImplementingIResponder( currentClass ) ) + { + return false; + } + final String functionName = computeFunctionName( functionAst ); + + return RESULT_FUNCTION_NAME.compareTo( functionName ) == 0 + || FAULT_FUNCTION_NAME.compareTo( functionName ) == 0; + } + + private IParserNode currentClass; + + /* + * (non-Javadoc) + * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority() + */ + @Override + protected final ViolationPriority getDefaultPriority() + { + return ViolationPriority.NORMAL; + } + + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#visitClass(com.adobe.ac + * .pmd.parser.IParserNode) + */ + @Override + protected final void visitClass( final IParserNode classNode ) + { + currentClass = classNode; + super.visitClass( classNode ); + } + + /* + * (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 final void visitFunction( final IParserNode functionAst, + final FunctionType type ) + { + setVariablesUnused( new LinkedHashMap< String, IParserNode >() ); + final boolean isOverriden = isFunctionOverriden( functionAst ); + + if ( !isOverriden + && !isResponderImplementation( currentClass, + functionAst ) && !isParsleyFunction( functionAst ) ) + { + super.visitFunction( functionAst, + type ); + + if ( !functionIsEventHandler( functionAst ) ) + { + for ( final String variableName : getVariablesUnused().keySet() ) + { + final IParserNode variable = getVariablesUnused().get( variableName ); + + addViolation( variable, + variable, + variableName ); + } + } + } + } + + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#visitParameters(com.adobe + * .ac.pmd.parser.IParserNode) + */ + @Override + protected final void visitParameters( final IParserNode ast ) + { + super.visitParameters( ast ); + + if ( ast.numChildren() != 0 ) + { + for ( final IParserNode parameterNode : ast.getChildren() ) + { + if ( !isParameterAnEvent( parameterNode ) + && parameterNode.numChildren() > 0 + && parameterNode.getChild( 0 ).numChildren() > 1 + && parameterNode.getChild( 0 ).getChild( 1 ).getStringValue().compareTo( DATA_GRID_COLUMN ) != 0 ) + { + addVariable( parameterNode.getChild( 0 ).getChild( 0 ).getStringValue(), + parameterNode ); + } + } + } + } + + private String extractFunctionName( final IParserNode ast ) + { + if ( ast.numChildren() != 0 ) + { + for ( final IParserNode node : ast.getChildren() ) + { + if ( node.is( NodeKind.NAME ) ) + { + return node.getStringValue(); + } + } + } + return ""; + } + + private boolean functionIsEventHandler( final IParserNode ast ) + { + final String functionName = extractFunctionName( ast ); + + return functionName.startsWith( "on" ) + || functionName.startsWith( "handle" ) || functionName.endsWith( "handler" ); + } + + private boolean isFunctionOverriden( final IParserNode ast ) + { + for ( final IParserNode child : ast.getChildren() ) + { + if ( child.is( NodeKind.MOD_LIST ) ) + { + for ( final IParserNode mod : child.getChildren() ) + { + if ( mod.getStringValue().equals( KeyWords.OVERRIDE.toString() ) ) + { + return true; + } + } + } + } + return false; + } + + private boolean isParameterAnEvent( final IParserNode parameterNode ) + { + final IParserNode parameterType = getTypeFromFieldDeclaration( parameterNode ); + + return parameterType != null + && parameterType.getStringValue() != null && parameterType.getStringValue().contains( "Event" ); + } + + private boolean isParsleyFunction( final IParserNode functionAst ) + { + for ( final IParserNode child : functionAst.getChildren() ) + { + if ( child.is( NodeKind.META_LIST ) ) + { + for ( final IParserNode metaDataChild : child.getChildren() ) + { + if ( metaDataChild.getStringValue() != null + && ParsleyMetaData.getPossibleMetaDataFromLocation( Location.FUNCTION ) + .containsKey( metaDataChild.getStringValue() ) ) + { + 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/unused/UnusedPrivateMethodRule.java ---------------------------------------------------------------------- diff --git a/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/unused/UnusedPrivateMethodRule.java b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/unused/UnusedPrivateMethodRule.java new file mode 100644 index 0000000..6637b4f --- /dev/null +++ b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/unused/UnusedPrivateMethodRule.java @@ -0,0 +1,183 @@ +/* + * 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.unused; + +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import com.adobe.ac.pmd.files.IAs3File; +import com.adobe.ac.pmd.nodes.IAttribute; +import com.adobe.ac.pmd.nodes.IClass; +import com.adobe.ac.pmd.nodes.IConstant; +import com.adobe.ac.pmd.nodes.IFunction; +import com.adobe.ac.pmd.nodes.IVariable; +import com.adobe.ac.pmd.nodes.Modifier; +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 UnusedPrivateMethodRule extends AbstractAstFlexRule +{ + private Map< String, IFunction > privateFunctions = null; + + /* + * (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 ) + { + fillPrivateFunctions( classNode.getFunctions() ); + findUnusedFunction( classNode.getBlock() ); + + super.findViolations( classNode ); + + addViolations(); + } + + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#findViolations(java.util + * .List) + */ + @Override + protected final void findViolations( final List< IFunction > functions ) + { + super.findViolations( functions ); + + for ( final IFunction function : functions ) + { + findUnusedFunction( function.getBody() ); + } + } + + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#findViolationsFromAttributes + * (java.util.List) + */ + @Override + protected void findViolationsFromAttributes( final List< IAttribute > variables ) + { + super.findViolationsFromAttributes( variables ); + + findViolationsFromVariables( variables ); + } + + /* + * (non-Javadoc) + * @see + * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#findViolationsFromConstants + * (java.util.List) + */ + @Override + protected void findViolationsFromConstants( final List< IConstant > constants ) + { + super.findViolationsFromConstants( constants ); + + findViolationsFromVariables( constants ); + } + + /* + * (non-Javadoc) + * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority() + */ + @Override + protected final ViolationPriority getDefaultPriority() + { + return ViolationPriority.NORMAL; + } + + private void addViolations() + { + final Set< Integer > ignoredLines = new HashSet< Integer >(); + + for ( final String functionName : privateFunctions.keySet() ) + { + final IFunction function = privateFunctions.get( functionName ); + ignoredLines.clear(); + ignoredLines.add( getNameFromFunctionDeclaration( function.getInternalNode() ).getLine() ); + + if ( getCurrentFile() instanceof IAs3File + || !getCurrentFile().contains( functionName, + ignoredLines ) ) + { + addViolation( function ); + } + } + } + + private void fillPrivateFunctions( final List< IFunction > functions ) + { + privateFunctions = new LinkedHashMap< String, IFunction >(); + + for ( final IFunction function : functions ) + { + if ( function.is( Modifier.PRIVATE ) ) + { + privateFunctions.put( function.getName(), + function ); + } + } + } + + private void findUnusedFunction( final IParserNode body ) + { + if ( body != null ) + { + if ( body.getStringValue() != null ) + { + for ( final String functionName : privateFunctions.keySet() ) + { + if ( body.getStringValue().equals( functionName ) ) + { + privateFunctions.remove( functionName ); + break; + } + } + } + if ( body.numChildren() != 0 ) + { + for ( final IParserNode child : body.getChildren() ) + { + findUnusedFunction( child ); + } + } + } + } + + private void findViolationsFromVariables( final List< ? extends IVariable > variables ) + { + for ( final IVariable constant : variables ) + { + if ( constant.getInitializationExpression() != null ) + { + findUnusedFunction( constant.getInitializationExpression().getInternalNode() ); + } + } + } +} http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e43b7a87/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/resources/com/adobe/ac/pmd/all_flex.xml ---------------------------------------------------------------------- diff --git a/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/resources/com/adobe/ac/pmd/all_flex.xml b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/resources/com/adobe/ac/pmd/all_flex.xml new file mode 100644 index 0000000..814086d --- /dev/null +++ b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/resources/com/adobe/ac/pmd/all_flex.xml @@ -0,0 +1,48 @@ +<?xml version="1.0"?> +<!-- + + 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. + +--> +<ruleset name="All Flex Rules" xmlns="http://pmd.sf.net/ruleset/1.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd" + xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd"> + + <description>Every Flex Rule in FlexPMD</description> + + <rule ref="com/adobe/ac/pmd/rulesets/architecture.xml" /> + <rule ref="com/adobe/ac/pmd/rulesets/asdocs.xml" /> + <rule ref="com/adobe/ac/pmd/rulesets/basic_mxml.xml" /> + <rule ref="com/adobe/ac/pmd/rulesets/binding.xml" /> + <rule ref="com/adobe/ac/pmd/rulesets/cairngorm.xml" /> + <rule ref="com/adobe/ac/pmd/rulesets/component.xml" /> + <rule ref="com/adobe/ac/pmd/rulesets/css.xml" /> + <rule ref="com/adobe/ac/pmd/rulesets/empty.xml" /> + <rule ref="com/adobe/ac/pmd/rulesets/event.xml" /> + <rule ref="com/adobe/ac/pmd/rulesets/indentation.xml" /> + <rule ref="com/adobe/ac/pmd/rulesets/maintanability.xml" /> + <rule ref="com/adobe/ac/pmd/rulesets/multitouch.xml" /> + <rule ref="com/adobe/ac/pmd/rulesets/naming.xml" /> + <rule ref="com/adobe/ac/pmd/rulesets/parsley.xml" /> + <rule ref="com/adobe/ac/pmd/rulesets/performance.xml" /> + <rule ref="com/adobe/ac/pmd/rulesets/sizing.xml" /> + <rule ref="com/adobe/ac/pmd/rulesets/style.xml" /> + <rule ref="com/adobe/ac/pmd/rulesets/switches.xml" /> + <rule ref="com/adobe/ac/pmd/rulesets/unittest.xml" /> + <rule ref="com/adobe/ac/pmd/rulesets/unused.xml" /> + +</ruleset> http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e43b7a87/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/resources/com/adobe/ac/pmd/default_flex.xml ---------------------------------------------------------------------- diff --git a/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/resources/com/adobe/ac/pmd/default_flex.xml b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/resources/com/adobe/ac/pmd/default_flex.xml new file mode 100644 index 0000000..ef8fd61 --- /dev/null +++ b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/resources/com/adobe/ac/pmd/default_flex.xml @@ -0,0 +1,46 @@ +<?xml version="1.0"?> +<!-- + + 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. + +--> +<ruleset name="Default Flex Rules" xmlns="http://pmd.sf.net/ruleset/1.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd" + xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd"> + + <description>Every Flex Rule in FlexPMD</description> + + <rule ref="com/adobe/ac/pmd/rulesets/architecture.xml" /> + <rule ref="com/adobe/ac/pmd/rulesets/basic_mxml.xml" /> + <rule ref="com/adobe/ac/pmd/rulesets/binding.xml" /> + <rule ref="com/adobe/ac/pmd/rulesets/cairngorm.xml" /> + <rule ref="com/adobe/ac/pmd/rulesets/component.xml" /> + <rule ref="com/adobe/ac/pmd/rulesets/css.xml" /> + <rule ref="com/adobe/ac/pmd/rulesets/empty.xml" /> + <rule ref="com/adobe/ac/pmd/rulesets/event.xml" /> + <rule ref="com/adobe/ac/pmd/rulesets/maintanability.xml" /> + <rule ref="com/adobe/ac/pmd/rulesets/naming.xml" /> + <rule ref="com/adobe/ac/pmd/rulesets/parsley.xml" /> + <rule ref="com/adobe/ac/pmd/rulesets/performance.xml" /> + <rule ref="com/adobe/ac/pmd/rulesets/security.xml" /> + <rule ref="com/adobe/ac/pmd/rulesets/sizing.xml" /> + <rule ref="com/adobe/ac/pmd/rulesets/style.xml" /> + <rule ref="com/adobe/ac/pmd/rulesets/switches.xml" /> + <rule ref="com/adobe/ac/pmd/rulesets/unittest.xml" /> + <rule ref="com/adobe/ac/pmd/rulesets/unused.xml" /> + +</ruleset> http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e43b7a87/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/resources/com/adobe/ac/pmd/rulesets/architecture.xml ---------------------------------------------------------------------- diff --git a/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/resources/com/adobe/ac/pmd/rulesets/architecture.xml b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/resources/com/adobe/ac/pmd/rulesets/architecture.xml new file mode 100644 index 0000000..82adbe2 --- /dev/null +++ b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/resources/com/adobe/ac/pmd/rulesets/architecture.xml @@ -0,0 +1,118 @@ +<?xml version="1.0"?> +<!-- + + 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. + +--> +<ruleset name="Architecture Rules" xmlns="http://pmd.sf.net/ruleset/1.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd" + xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd"> + + <description> + The Architecture ruleset contains a collection of good practices around architecture. + </description> + + <rule class="com.adobe.ac.pmd.rules.architecture.ViewComponentReferencedInModelRule" + message="A view component should not be referenced in a model class"> + <description></description> + <priority>3</priority> + <example> +package com.adobe.ac +{ + import mx.controls.ComboBox; // VIOLATION + + public class MyModelClass + { + } +} + </example> + </rule> + + <rule class="com.adobe.ac.pmd.rules.architecture.MonkeyPatchingRule" + message="This class looks to be duplicated with a SDK class"> + <description>Monkey patching can be a risky undertaking because it is not using intended extensibility points and thus may have unintended consequences or make migration to newer versions of the SDK more difficult</description> + <priority>1</priority> + </rule> + + <rule class="com.adobe.ac.pmd.rules.architecture.UseInternalClassOutsideApiClass" + message="This class imports an internal class ({0}) from another function area ({1})"> + <description>If you have different functionalities, you probably don't want every class of each to be accessible from any other functional areas. +So you probably want to use this packaging: +[org].[project].func1.api +[org].[project].func1.restricted +[org].[project].func2.api +[org].[project].func2.restricted +This rule makes sure that no restricted classes is accessed from outside its own function area. + </description> + <priority>1</priority> + <example> +package functional +{ + import functional.func1.api.Func1ExposedClass; + import functional.func1.restricted.Func1RestrictedClass; // VIOLATION + import functional.func2.api.Func2ExposedClass; + import functional.func2.restricted.Func2RestrictedClass; // VIOLATION + + public class FunctionClient + { + } +} +package functional.func1.api + +{ + import functional.func1.restricted.Func1RestrictedClass; + import functional.func2.api.Func2ExposedClass; + import functional.func2.restricted.Func2RestrictedClass; // VIOLATION + + public class Func1ExposedClass + { + } +} +package functional.func1.restricted +{ + import functional.func1.api.Func1ExposedClass; + import functional.func2.api.Func2ExposedClass; + import functional.func2.restricted.Func2RestrictedClass; // VIOLATION + + public class Func1RestrictedClass + { + } +} +package functional.func2.api +{ + import functional.func1.api.Func1ExposedClass; + import functional.func1.restricted.Func1RestrictedClass; // VIOLATION + import functional.func2.restricted.Func2RestrictedClass; + + public class Func2ExposedClass + { + } +} +package functional.func2.restricted +{ + import functional.func1.api.Func1ExposedClass; + import functional.func1.restricted.Func1RestrictedClass; // VIOLATION + import functional.func2.api.Func2ExposedClass; + + public class Func2RestrictedClass + { + } +} + </example> + </rule> + +</ruleset> http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e43b7a87/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/resources/com/adobe/ac/pmd/rulesets/asdocs.xml ---------------------------------------------------------------------- diff --git a/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/resources/com/adobe/ac/pmd/rulesets/asdocs.xml b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/resources/com/adobe/ac/pmd/rulesets/asdocs.xml new file mode 100644 index 0000000..3877230 --- /dev/null +++ b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/resources/com/adobe/ac/pmd/rulesets/asdocs.xml @@ -0,0 +1,50 @@ +<?xml version="1.0"?> +<!-- + + 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. + +--> +<ruleset + name="AsDocs Rules" + xmlns="http://pmd.sf.net/ruleset/1.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd" + xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd" + > + + <description> + The AsDocs Ruleset contains a collection of good practices related to AsDocs. + </description> + + <rule + class="com.adobe.ac.pmd.rules.asdocs.AttributeAsDocMissingRule" + message="This attribute ({0}) should be documented with AsDocs."> + <priority>3</priority> + </rule> + + <rule + class="com.adobe.ac.pmd.rules.asdocs.ClassAsDocMissingRule" + message="This class ({0}) should be documented with AsDocs."> + <priority>3</priority> + </rule> + + <rule + class="com.adobe.ac.pmd.rules.asdocs.MethodAsDocMissingRule" + message="This method ({0}) should be documented with AsDocs."> + <priority>3</priority> + </rule> + +</ruleset> http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e43b7a87/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/resources/com/adobe/ac/pmd/rulesets/basic_mxml.xml ---------------------------------------------------------------------- diff --git a/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/resources/com/adobe/ac/pmd/rulesets/basic_mxml.xml b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/resources/com/adobe/ac/pmd/rulesets/basic_mxml.xml new file mode 100644 index 0000000..2f9fcf5 --- /dev/null +++ b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/resources/com/adobe/ac/pmd/rulesets/basic_mxml.xml @@ -0,0 +1,65 @@ +<?xml version="1.0"?> +<!-- + + 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. + +--> +<ruleset name="Basic MXML Rules" xmlns="http://pmd.sf.net/ruleset/1.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd" + xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd"> + + <description> + The Basic MXML Ruleset contains a collection of good practices which everyone should follow. + </description> + + <rule class="com.adobe.ac.pmd.rules.mxml.MoreThanOneEntryPointInMxmlRule" + message="There is more than 1 public variable in this MXML component"> + <priority>5</priority> + </rule> + + <rule class="com.adobe.ac.pmd.rules.mxml.MoreThanTwoEntryPointsInMxmlRule" + message="There are more than 2 public variables in this MXML component"> + <priority>3</priority> + </rule> + + <rule class="com.adobe.ac.pmd.rules.mxml.TooLongScriptBlockRule" + message="This script block is too long ({0} maximum, but {1} actually)"> + <priority>3</priority> + <properties> + <property name="maximum"> + <value>50</value> + </property> + </properties> + </rule> + + <rule class="com.adobe.ac.pmd.rules.mxml.CodeBehindInMxmlRule" + message="Avoid using code behind files"> + <description>Code behind files are tightly coupled with the view, not unit-testable, not easy to navigate the code code base and not reusable. Try using presentation model pattern, or observer pattern</description> + <priority>5</priority> + </rule> + + <rule class="com.adobe.ac.pmd.rules.mxml.TooManyStatesInMxmlRule" + message="Having too many states does not help visibility. Try to refactor this view component."> + <priority>3</priority> + <properties> + <property name="maximum"> + <value>5</value> + </property> + </properties> + </rule> + +</ruleset> http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e43b7a87/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/resources/com/adobe/ac/pmd/rulesets/binding.xml ---------------------------------------------------------------------- diff --git a/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/resources/com/adobe/ac/pmd/rulesets/binding.xml b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/resources/com/adobe/ac/pmd/rulesets/binding.xml new file mode 100644 index 0000000..0eedc46 --- /dev/null +++ b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/resources/com/adobe/ac/pmd/rulesets/binding.xml @@ -0,0 +1,70 @@ +<?xml version="1.0"?> +<!-- + + 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. + +--> +<ruleset name="Binding Rules" xmlns="http://pmd.sf.net/ruleset/1.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd" + xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd"> + + <description> + The Binding ruleset contains a collection of good practices around usage of binding. + </description> + + <rule class="com.adobe.ac.pmd.rules.binding.BindingUtilsRule" + message="BindingUtils class uses hard coded strings, which won't be picked up by the compiler if you rename this attribute. You should probably consider refactoring using events"> + <description></description> + <priority>1</priority> + <example> +public class Controller extends FrontController +{ + public function Controller() + { + BindingUtils.bindSetter(setContent, value, "content"); // VIOLATION + } +} + </example> + </rule> + + <rule class="com.adobe.ac.pmd.rules.binding.ChangeWatcherRule" + message="ChangeWatcher class uses hard coded strings to specify the attribute name, to listen to. Prefer listening to events or setters"> + <priority>1</priority> + <example> +public final class Title +{ + private var watcher : ChangeWatcher; // VIOLATION +} + </example> + </rule> + + <rule class="com.adobe.ac.pmd.rules.binding.TooLongBindingExpressionRule" + message="This binding expression is too long ({0} dots maximum, but {1} actually)"> + <description>A Binding expression is executed as soon as one of the bindable attributes changed. If a binding expression contains too many expression, there could be some performance issue.</description> + <priority>3</priority> + <properties> + <property name="maximum"> + <value>3</value> + </property> + </properties> + <example> + <![CDATA[ +<mx:Label text="{ vfrfr.frfr.frf.lala }"/> <!-- Violation--> + ]]> + </example> + </rule> +</ruleset> http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e43b7a87/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/resources/com/adobe/ac/pmd/rulesets/cairngorm.xml ---------------------------------------------------------------------- diff --git a/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/resources/com/adobe/ac/pmd/rulesets/cairngorm.xml b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/resources/com/adobe/ac/pmd/rulesets/cairngorm.xml new file mode 100644 index 0000000..43b425c --- /dev/null +++ b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/resources/com/adobe/ac/pmd/rulesets/cairngorm.xml @@ -0,0 +1,134 @@ +<?xml version="1.0"?> +<!-- + + 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. + +--> +<ruleset name="Cairngorm Rules" xmlns="http://pmd.sf.net/ruleset/1.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd" + xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd"> + <description> + The Cairngorm Ruleset contains a collection of good practices related to Cairngorm. + </description> + + <rule class="com.adobe.ac.pmd.rules.cairngorm.BindableModelLocatorRule" + message="A modelLocator must not be Bindable at a class level"> + <description>A bindable ModelLocator could leads to performance issues due to bindings</description> + <priority>1</priority> + <example> +[Bindable] +public class BindableModelLocator // VIOLATION +{ +} + </example> + </rule> + + <rule + class="com.adobe.ac.pmd.rules.cairngorm.ReferenceModelLocatorOutsideTheMainApplicationRule" + message="The ModelLocator should be only accessible from the main application file"> + <description>The ModelLocator should be only accessible from the main application file. Then sub-models should be injected to the nested views.</description> + <priority>3</priority> + <example> +package business +{ + import model.MyModelLocator; // VIOLATION + + public class MyBusinessClass + { + } +} + </example> + </rule> + + <rule class="com.adobe.ac.pmd.rules.cairngorm.FatControllerRule" + message="A FrontController must nor add all its commands within the Controller constructor"> + <description>Try split them into methods where you add commands depending on their functional area.</description> + <priority>3</priority> + <example> +package control +{ + import control.GetItems1Command; + import control.GetItems1Event; + import control.GetItems2Command; + import control.GetItems2Event; + // A lot of other imports + + public class MyFrontController // VIOLATION + { + public function MyFrontController() + { + addCommand( + GetItems1Event.EVENT_NAME, + GetItems1Command ); + + addCommand( + GetItems2Event.EVENT_NAME, + GetItems2Command ); + + // A lot of other addCommand + } + } +} + </example> + </rule> + + <rule + class="com.adobe.ac.pmd.rules.cairngorm.BadCairngormEventNameFormatRule" + message="A Cairngorm event name should contain the function area name before the actual event name"> + <description>You would have something like 'productManagement.getProducts' as an event name.</description> + <priority>3</priority> + <example> + +public class UncorrectConstructorEvent extends CairngormEvent +{ + public function UncorrectConstructorEvent( model : IModel ) + { + super( "eventName", model ); // VIOLATION. It should be "functionalArea.eventName" instead + } +} +public class UncorrectConstantEvent extends CairngormEnterpriseEvent +{ + public static const EVENT_NAME : String = "eventName"; + + public function UncorrectConstantEvent( model : IModel ) + { + super( EVENT_NAME, model ); // VIOLATION + } +} + </example> + </rule> + + <rule class="com.adobe.ac.pmd.rules.cairngorm.CairngormEventDispatcherCallExplicitlyRule" + message="CairngormEventDispatcher is called explicitly. {0}"> + <priority>3</priority> + <example> + <![CDATA[ +public function foo() : void +{ + CairngormEventDispatcher.getInstance().dispatchEvent(new Event(CONSTANT)); // VIOLATION <- use cairngormEvent.dispatch(); + CairngormEventDispatcher.getInstance().addEventListener(CONSTANT, onHearing); // VIOLATION <- MVC broken +} + ]]> + </example> + </rule> + + <rule class="com.adobe.ac.pmd.rules.cairngorm.ModelLocatorReferencedMoreThanOncePerClassRule" + message="Only one reference of ModelLocator is allowed per class"> + <priority>3</priority> + </rule> + +</ruleset> http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e43b7a87/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/resources/com/adobe/ac/pmd/rulesets/component.xml ---------------------------------------------------------------------- diff --git a/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/resources/com/adobe/ac/pmd/rulesets/component.xml b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/resources/com/adobe/ac/pmd/rulesets/component.xml new file mode 100644 index 0000000..daba3e1 --- /dev/null +++ b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/resources/com/adobe/ac/pmd/rulesets/component.xml @@ -0,0 +1,43 @@ +<?xml version="1.0"?> +<!-- + + 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. + +--> +<ruleset name="Custom component rules" xmlns="http://pmd.sf.net/ruleset/1.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd" + xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd"> + + <description> + The Component Ruleset contains a collection of good practices related to custom component development. + </description> + + <rule + class="com.adobe.ac.pmd.rules.component.UpdateChildrenNumberInUpdateDisplayListRule" + message="Flex specific - Do not add or remove displayable children from updateDisplayList"> + <description>UpdateDisplayList is called everytime a child is invalidated. So calling addChild or removeChild in this function could be really CPU consuming</description> + <priority>1</priority> + <example></example> + </rule> + + <rule class="com.adobe.ac.pmd.rules.component.CallLaterDirectlyRule" + message="Flex specific - Don't call 'callLater' explicitly"> + <description>If you needed to call 'callLater' explicitly, then you probably did not extend the correct component life cycle.</description> + <priority>1</priority> + </rule> + +</ruleset> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e43b7a87/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/resources/com/adobe/ac/pmd/rulesets/css.xml ---------------------------------------------------------------------- diff --git a/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/resources/com/adobe/ac/pmd/rulesets/css.xml b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/resources/com/adobe/ac/pmd/rulesets/css.xml new file mode 100644 index 0000000..c580d39 --- /dev/null +++ b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/resources/com/adobe/ac/pmd/rulesets/css.xml @@ -0,0 +1,41 @@ +<?xml version="1.0"?> +<!-- + + 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. + +--> +<ruleset name="CSS Rules" xmlns="http://pmd.sf.net/ruleset/1.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd" + xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd"> + + <description> + The Styling Ruleset contains a collection of good practices related to + styling. + </description> + + <rule class="com.adobe.ac.pmd.rules.css.StyleBlockInMxmlRule" + message="The style block is embed in the MXML file"> + <description>It is not a good practice to embed style blocks inside the MXML component. Prefer using external CSS files.</description> + <priority>3</priority> + </rule> + + <rule class="com.adobe.ac.pmd.rules.css.UseCssInsteadOfEmbedMetaDataRule" + message="Embed metadata detected in source code where a stylesheet may be cleaner"> + <priority>5</priority> + </rule> + +</ruleset> http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/e43b7a87/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/resources/com/adobe/ac/pmd/rulesets/empty.xml ---------------------------------------------------------------------- diff --git a/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/resources/com/adobe/ac/pmd/rulesets/empty.xml b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/resources/com/adobe/ac/pmd/rulesets/empty.xml new file mode 100644 index 0000000..e6f46c3 --- /dev/null +++ b/FlexPMD/flex-pmd-java/flex-pmd-ruleset/src/main/resources/com/adobe/ac/pmd/rulesets/empty.xml @@ -0,0 +1,66 @@ +<?xml version="1.0"?> +<!-- + + 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. + +--> +<ruleset name="Empty statement Rules" xmlns="http://pmd.sf.net/ruleset/1.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd" + xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd"> + + <description> + The Empty ruleset contains a collection of rules detecting empty statements. + </description> + + <rule class="com.adobe.ac.pmd.rules.empty.EmptyCatchStatementRule" + message="This catch statement is empty"> + <priority>3</priority> + <example> +public class Foo +{ + public function bar( x : int ) : void + { + try + { + } + catch( e : Exception ) // VIOLATION + { + } + } +} + </example> + </rule> + + <rule class="com.adobe.ac.pmd.rules.empty.EmptyIfStmtRule" + message="No statements in this if statement"> + <description>Empty If Statement finds instances where a condition is checked but nothing is done about it. </description> + <priority>3</priority> + <example> +public class Foo +{ + public function bar( x : int ) : void + { + if ( x == 0 ) + { + // VIOLATION + } + } +} + </example> + </rule> + +</ruleset>