You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by ah...@apache.org on 2014/04/25 08:18:14 UTC
[15/46] FlexPMD Donation from Adobe Systems Inc
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/b0fc5f17/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/UselessOverridenFunctionRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/UselessOverridenFunctionRule.java b/FlexPMD/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-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/b0fc5f17/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/forbiddentypes/AbstractUseForbiddenTypeRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/forbiddentypes/AbstractUseForbiddenTypeRule.java b/FlexPMD/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-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/b0fc5f17/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/forbiddentypes/UseDictionaryTypeRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/forbiddentypes/UseDictionaryTypeRule.java b/FlexPMD/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-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/b0fc5f17/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/forbiddentypes/UseGenericTypeRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/forbiddentypes/UseGenericTypeRule.java b/FlexPMD/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-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/b0fc5f17/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/forbiddentypes/UseObjectTypeRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/maintanability/forbiddentypes/UseObjectTypeRule.java b/FlexPMD/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-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/b0fc5f17/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/multiscreen/AvoidRollMouseEventRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/multiscreen/AvoidRollMouseEventRule.java b/FlexPMD/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-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/b0fc5f17/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/multiscreen/AvoidTooltipRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/multiscreen/AvoidTooltipRule.java b/FlexPMD/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-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/b0fc5f17/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/mxml/AbstractMoreThanEntryPointInMxmlRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/mxml/AbstractMoreThanEntryPointInMxmlRule.java b/FlexPMD/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-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/b0fc5f17/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/mxml/CodeBehindInMxmlRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/mxml/CodeBehindInMxmlRule.java b/FlexPMD/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-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/b0fc5f17/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/mxml/MoreThanOneEntryPointInMxmlRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/mxml/MoreThanOneEntryPointInMxmlRule.java b/FlexPMD/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-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/b0fc5f17/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/mxml/MoreThanTwoEntryPointsInMxmlRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/mxml/MoreThanTwoEntryPointsInMxmlRule.java b/FlexPMD/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-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/b0fc5f17/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/mxml/OnlyOneScriptBlockPerMxmlRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/mxml/OnlyOneScriptBlockPerMxmlRule.java b/FlexPMD/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-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/b0fc5f17/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/mxml/StaticMethodInMxmlRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/mxml/StaticMethodInMxmlRule.java b/FlexPMD/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-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/b0fc5f17/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/mxml/TooLongScriptBlockRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/mxml/TooLongScriptBlockRule.java b/FlexPMD/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-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/b0fc5f17/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/mxml/TooManyStatesInMxmlRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/mxml/TooManyStatesInMxmlRule.java b/FlexPMD/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-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/b0fc5f17/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/naming/BooleanAttributeShouldContainIsHasRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/naming/BooleanAttributeShouldContainIsHasRule.java b/FlexPMD/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-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/b0fc5f17/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/naming/CapitalizeConstantsRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/naming/CapitalizeConstantsRule.java b/FlexPMD/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-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;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/b0fc5f17/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/naming/IncorrectClassCase.java
----------------------------------------------------------------------
diff --git a/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/naming/IncorrectClassCase.java b/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/naming/IncorrectClassCase.java
new file mode 100644
index 0000000..560ca56
--- /dev/null
+++ b/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/naming/IncorrectClassCase.java
@@ -0,0 +1,56 @@
+/*
+ * 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 com.adobe.ac.pmd.nodes.IClass;
+import com.adobe.ac.pmd.rules.core.AbstractAstFlexRule;
+import com.adobe.ac.pmd.rules.core.ViolationPosition;
+import com.adobe.ac.pmd.rules.core.ViolationPriority;
+
+/**
+ * @author xagnetti
+ */
+public class IncorrectClassCase 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 char firstChar = classNode.getName().charAt( 0 );
+
+ if ( firstChar < 'A'
+ || firstChar > 'Z' )
+ {
+ addViolation( new ViolationPosition( 1, getCurrentFile().getLinesNb() ) );
+ }
+ }
+
+ /*
+ * (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/b0fc5f17/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/naming/IncorrectEventHandlerNameRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/naming/IncorrectEventHandlerNameRule.java b/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/naming/IncorrectEventHandlerNameRule.java
new file mode 100644
index 0000000..81b3506
--- /dev/null
+++ b/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/naming/IncorrectEventHandlerNameRule.java
@@ -0,0 +1,79 @@
+/*
+ * 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.LinkedHashMap;
+import java.util.Map;
+
+import net.sourceforge.pmd.PropertyDescriptor;
+import net.sourceforge.pmd.properties.StringProperty;
+
+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;
+
+public class IncorrectEventHandlerNameRule extends AbstractAstFlexRule
+{
+ private static final String DEFAULT_PREFIX = "on";
+ private static final String DEFAULT_SUFFIX = "";
+ private static final String PREFIX_NAME = "prefix";
+ private static final String SUFFIX_NAME = "suffix";
+ private final String prefix;
+ private final String suffix;
+
+ public IncorrectEventHandlerNameRule()
+ {
+ super();
+ prefix = getStringProperty( propertyDescriptorFor( PREFIX_NAME ) );
+ suffix = getStringProperty( propertyDescriptorFor( SUFFIX_NAME ) );
+ }
+
+ @Override
+ protected void findViolations( final IFunction function )
+ {
+ if ( function.isEventHandler()
+ && !( function.getName().startsWith( prefix ) && function.getName().endsWith( suffix ) ) )
+ {
+ final IParserNode name = getNameFromFunctionDeclaration( function.getInternalNode() );
+
+ addViolation( name,
+ name.getStringValue(),
+ prefix,
+ suffix );
+ }
+ }
+
+ @Override
+ protected ViolationPriority getDefaultPriority()
+ {
+ return ViolationPriority.LOW;
+ }
+
+ @Override
+ protected final Map< String, PropertyDescriptor > propertiesByName()
+ {
+ final Map< String, PropertyDescriptor > properties = new LinkedHashMap< String, PropertyDescriptor >();
+
+ properties.put( PREFIX_NAME,
+ new StringProperty( PREFIX_NAME, "", DEFAULT_PREFIX, properties.size() ) );
+ properties.put( SUFFIX_NAME,
+ new StringProperty( SUFFIX_NAME, "", DEFAULT_SUFFIX, properties.size() ) );
+
+ return properties;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/b0fc5f17/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/naming/InterfaceNamingRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/naming/InterfaceNamingRule.java b/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/naming/InterfaceNamingRule.java
new file mode 100644
index 0000000..77dcb4d
--- /dev/null
+++ b/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/naming/InterfaceNamingRule.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.naming;
+
+import com.adobe.ac.pmd.nodes.IClass;
+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 InterfaceNamingRule extends AbstractAstFlexRule
+{
+ @Override
+ protected void findViolations( final IClass classNode )
+ {
+ if ( classNode.getInternalNode().is( NodeKind.INTERFACE )
+ && !classNode.getName().startsWith( "I" ) )
+ {
+ addViolation( classNode );
+ }
+ }
+
+ @Override
+ protected ViolationPriority getDefaultPriority()
+ {
+ return ViolationPriority.HIGH;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/b0fc5f17/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/naming/PackageCaseRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/naming/PackageCaseRule.java b/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/naming/PackageCaseRule.java
new file mode 100644
index 0000000..005a621
--- /dev/null
+++ b/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/naming/PackageCaseRule.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.naming;
+
+import com.adobe.ac.pmd.IFlexViolation;
+import com.adobe.ac.pmd.nodes.IPackage;
+import com.adobe.ac.pmd.rules.core.AbstractAstFlexRule;
+import com.adobe.ac.pmd.rules.core.ViolationPriority;
+
+/**
+ * @author xagnetti
+ */
+public class PackageCaseRule 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 )
+ {
+ if ( containsUpperCharacter( packageNode.getName() ) )
+ {
+ final IFlexViolation violation = addViolation( packageNode,
+ packageNode.getName() );
+
+ violation.setEndColumn( packageNode.getName().length()
+ + violation.getBeginColumn() );
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority()
+ */
+ @Override
+ protected final ViolationPriority getDefaultPriority()
+ {
+ return ViolationPriority.NORMAL;
+ }
+
+ private boolean containsUpperCharacter( final String packageName )
+ {
+ boolean found = false;
+
+ for ( int i = 1; i < packageName.length(); i++ )
+ {
+ final char currentChar = packageName.charAt( i );
+
+ if ( currentChar >= 'A'
+ && currentChar <= 'Z' && packageName.charAt( i - 1 ) == '.' )
+ {
+ found = true;
+
+ break;
+ }
+ }
+ return found;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/b0fc5f17/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/naming/PropertyHiddenByLocalVariableRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/naming/PropertyHiddenByLocalVariableRule.java b/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/naming/PropertyHiddenByLocalVariableRule.java
new file mode 100644
index 0000000..6c0dcaa
--- /dev/null
+++ b/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/naming/PropertyHiddenByLocalVariableRule.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 java.util.Set;
+
+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.nodes.IVariable;
+import com.adobe.ac.pmd.rules.core.AbstractAstFlexRule;
+import com.adobe.ac.pmd.rules.core.ViolationPriority;
+
+/**
+ * @author xagnetti
+ */
+public class PropertyHiddenByLocalVariableRule 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 List< IAttribute > variables = classNode.getAttributes();
+
+ if ( classNode.getFunctions() != null )
+ {
+ for ( final IFunction function : classNode.getFunctions() )
+ {
+ final Set< String > localVariables = function.getLocalVariables().keySet();
+
+ for ( final String localVariable : localVariables )
+ {
+ for ( final IVariable field : variables )
+ {
+ if ( localVariable.equals( field.getName() ) )
+ {
+ addViolation( function.getLocalVariables().get( localVariable ),
+ field.getName() );
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /*
+ * (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/b0fc5f17/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/naming/TooLongFunctionNameRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/naming/TooLongFunctionNameRule.java b/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/naming/TooLongFunctionNameRule.java
new file mode 100644
index 0000000..b7d319f
--- /dev/null
+++ b/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/naming/TooLongFunctionNameRule.java
@@ -0,0 +1,55 @@
+/*
+ * 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 com.adobe.ac.pmd.nodes.IFunction;
+import com.adobe.ac.pmd.rules.core.ViolationPriority;
+import com.adobe.ac.pmd.rules.core.thresholded.AbstractMaximizedAstFlexRule;
+
+public class TooLongFunctionNameRule extends AbstractMaximizedAstFlexRule
+{
+ private static final int DEFAULT_THRESHOLD = 25;
+ private int currentMethodNameLength;
+
+ @Override
+ public int getActualValueForTheCurrentViolation()
+ {
+ return currentMethodNameLength;
+ }
+
+ @Override
+ public int getDefaultThreshold()
+ {
+ return DEFAULT_THRESHOLD;
+ }
+
+ @Override
+ protected void findViolations( final IFunction function )
+ {
+ currentMethodNameLength = function.getName().length();
+ if ( currentMethodNameLength > getThreshold() )
+ {
+ addViolation( function );
+ }
+ }
+
+ @Override
+ protected ViolationPriority getDefaultPriority()
+ {
+ return ViolationPriority.NORMAL;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/b0fc5f17/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/naming/TooShortVariableRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/naming/TooShortVariableRule.java b/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/naming/TooShortVariableRule.java
new file mode 100644
index 0000000..6536e90
--- /dev/null
+++ b/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/naming/TooShortVariableRule.java
@@ -0,0 +1,151 @@
+/*
+ * 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.Map;
+import java.util.regex.Matcher;
+
+import net.sourceforge.pmd.PropertyDescriptor;
+
+import com.adobe.ac.pmd.rules.core.AbstractRegexpBasedRule;
+import com.adobe.ac.pmd.rules.core.ViolationPriority;
+import com.adobe.ac.pmd.rules.core.thresholded.IThresholdedRule;
+
+/**
+ * @author xagnetti
+ */
+public class TooShortVariableRule extends AbstractRegexpBasedRule implements IThresholdedRule
+{
+ public static final int DEFAULT_THRESHOLD = 3;
+ private int length;
+
+ /*
+ * (non-Javadoc)
+ * @seecom.adobe.ac.pmd.rules.core.thresholded.IThresholdedRule#
+ * getActualValueForTheCurrentViolation()
+ */
+ public final int getActualValueForTheCurrentViolation()
+ {
+ return length;
+ }
+
+ /*
+ * (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#isConcernedByTheCurrentFile()
+ */
+ @Override
+ public final boolean isConcernedByTheCurrentFile()
+ {
+ return true;
+ }
+
+ /*
+ * (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.AbstractRegexpBasedRule#getRegexp()
+ */
+ @Override
+ protected final String getRegexp()
+ {
+ return ".*var (.*):.*";
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractRegexpBasedRule#isCurrentLineConcerned
+ * (java.lang.String)
+ */
+ @Override
+ protected boolean isCurrentLineConcerned( final String line )
+ {
+ return line.contains( "var" );
+ }
+
+ /*
+ * (non-Javadoc)
+ * @seecom.adobe.ac.pmd.rules.core.AbstractRegexpBasedRule#
+ * isViolationDetectedOnThisMatchingLine(java.lang.String)
+ */
+ @Override
+ protected final boolean isViolationDetectedOnThisMatchingLine( final String line )
+ {
+ final Matcher matcher = getMatcher( line );
+ boolean result = false;
+
+ if ( !line.contains( "for" )
+ && matcher.matches() )
+ {
+ length = matcher.group( 1 ).trim().length();
+
+ result = length < getThreshold();
+ }
+ return result;
+ }
+
+ /*
+ * (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/b0fc5f17/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/naming/VariableNameEndingWithNumericRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/naming/VariableNameEndingWithNumericRule.java b/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/naming/VariableNameEndingWithNumericRule.java
new file mode 100644
index 0000000..4328498
--- /dev/null
+++ b/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/naming/VariableNameEndingWithNumericRule.java
@@ -0,0 +1,111 @@
+/*
+ * 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.IClass;
+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;
+
+/**
+ * @author xagnetti
+ */
+public class VariableNameEndingWithNumericRule 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 )
+ {
+ super.findViolations( classNode );
+
+ findViolationsInNamableList( classNode.getAttributes() );
+ findViolationsInNamableList( classNode.getConstants() );
+ findViolationsInNamableList( classNode.getFunctions() );
+ }
+
+ /*
+ * (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 )
+ {
+ findViolationsInNamableList( function.getParameters() );
+
+ for ( final String variableName : function.getLocalVariables().keySet() )
+ {
+ if ( isNameEndsWithNumeric( variableName ) )
+ {
+ addViolation( function.getLocalVariables().get( variableName ),
+ variableName );
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority()
+ */
+ @Override
+ protected final ViolationPriority getDefaultPriority()
+ {
+ return ViolationPriority.NORMAL;
+ }
+
+ private void findViolationsInNamableList( final List< ? extends INamableNode > namables )
+ {
+ for ( final INamableNode namable : namables )
+ {
+ if ( isNameEndsWithNumeric( namable.getName() ) )
+ {
+ if ( namable instanceof IFunction )
+ {
+ final IFunction function = ( IFunction ) namable;
+
+ addViolation( function,
+ function.getName() );
+ }
+ else
+ {
+ addViolation( namable,
+ namable.getName() );
+ }
+ }
+ }
+ }
+
+ private boolean isNameEndsWithNumeric( final String name )
+ {
+ if ( name.length() == 0 )
+ {
+ return false;
+ }
+ final char lastCharacter = name.charAt( name.length() - 1 );
+
+ return Character.isDigit( lastCharacter );
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/b0fc5f17/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/naming/WronglyNamedVariableRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/naming/WronglyNamedVariableRule.java b/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/naming/WronglyNamedVariableRule.java
new file mode 100644
index 0000000..d27a8ac
--- /dev/null
+++ b/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/naming/WronglyNamedVariableRule.java
@@ -0,0 +1,121 @@
+/*
+ * 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.Collection;
+import java.util.List;
+import java.util.Map.Entry;
+
+import com.adobe.ac.pmd.nodes.IAttribute;
+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.parser.IParserNode;
+import com.adobe.ac.pmd.rules.core.AbstractAstFlexRule;
+import com.adobe.ac.pmd.rules.core.ViolationPriority;
+
+/**
+ * @author xagnetti
+ */
+public class WronglyNamedVariableRule extends AbstractAstFlexRule
+{
+ private static final String[] FORBIDDEN_NAMES =
+ { "tmp",
+ "temp",
+ "foo",
+ "bar",
+ "object",
+ "evt" };
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#findViolations(java.util
+ * .List)
+ */
+ @Override
+ protected final void findViolations( final List< IFunction > functions )
+ {
+ for ( final IFunction function : functions )
+ {
+ findViolationsInVariables( function.getParameters() );
+
+ for ( final Entry< String, IParserNode > variableNameEntrySet : function.getLocalVariables()
+ .entrySet() )
+ {
+ checkWronglyNamedVariable( variableNameEntrySet.getKey(),
+ variableNameEntrySet.getValue() );
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#findViolationsFromAttributes
+ * (java.util.List)
+ */
+ @Override
+ protected final void findViolationsFromAttributes( final List< IAttribute > attributes )
+ {
+ findViolationsInVariables( attributes );
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#findViolationsFromConstants
+ * (java.util.List)
+ */
+ @Override
+ protected final void findViolationsFromConstants( final List< IConstant > constants )
+ {
+ findViolationsInVariables( constants );
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority()
+ */
+ @Override
+ protected final ViolationPriority getDefaultPriority()
+ {
+ return ViolationPriority.NORMAL;
+ }
+
+ private void checkWronglyNamedVariable( final String variableName,
+ final IParserNode variableNode )
+ {
+ for ( final String forbiddenName : FORBIDDEN_NAMES )
+ {
+ if ( variableName.startsWith( forbiddenName ) )
+ {
+ addViolation( variableNode,
+ variableName );
+ }
+ }
+ }
+
+ private void findViolationsInVariables( final Collection< ? extends IVariable > variables )
+ {
+ for ( final IVariable variable : variables )
+ {
+ checkWronglyNamedVariable( variable.getName(),
+ variable.getInternalNode() );
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/b0fc5f17/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/parameterized/ParameterizedRegExpBasedRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/parameterized/ParameterizedRegExpBasedRule.java b/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/parameterized/ParameterizedRegExpBasedRule.java
new file mode 100644
index 0000000..36a9f3d
--- /dev/null
+++ b/FlexPMD/flex-pmd-ruleset/src/main/java/com/adobe/ac/pmd/rules/parameterized/ParameterizedRegExpBasedRule.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.parameterized;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import net.sourceforge.pmd.PropertyDescriptor;
+import net.sourceforge.pmd.properties.StringProperty;
+
+import com.adobe.ac.pmd.rules.core.AbstractRegexpBasedRule;
+import com.adobe.ac.pmd.rules.core.ViolationPriority;
+
+/**
+ * @author xagnetti
+ */
+public class ParameterizedRegExpBasedRule extends AbstractRegexpBasedRule
+{
+ public static final String PROPERTY_NAME = "expression";
+
+ /*
+ * (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.AbstractRegexpBasedRule#getRegexp()
+ */
+ @Override
+ protected String getRegexp()
+ {
+ return getStringProperty( propertyDescriptorFor( PROPERTY_NAME ) );
+ }
+
+ /*
+ * (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;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see net.sourceforge.pmd.CommonAbstractRule#propertiesByName()
+ */
+ @Override
+ protected final Map< String, PropertyDescriptor > propertiesByName()
+ {
+ final Map< String, PropertyDescriptor > properties = new LinkedHashMap< String, PropertyDescriptor >();
+
+ properties.put( PROPERTY_NAME,
+ new StringProperty( PROPERTY_NAME, "", "", properties.size() ) );
+
+ return properties;
+ }
+}