You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by cd...@apache.org on 2015/03/07 13:06:54 UTC
[01/24] git commit: [flex-utilities]
[refs/heads/feature/pmd-5.2-language-module] - Initial commit of the PMD
language module for Apache Flex
Repository: flex-utilities
Updated Branches:
refs/heads/feature/pmd-5.2-language-module [created] ff722d6f5
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/utils/src/main/java/org/apache/flex/pmd/utils/FlexFilter.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/utils/src/main/java/org/apache/flex/pmd/utils/FlexFilter.java b/FlexPMD/language-module/utils/src/main/java/org/apache/flex/pmd/utils/FlexFilter.java
new file mode 100644
index 0000000..8209330
--- /dev/null
+++ b/FlexPMD/language-module/utils/src/main/java/org/apache/flex/pmd/utils/FlexFilter.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 org.apache.flex.pmd.utils;
+
+import java.io.File;
+import java.io.FilenameFilter;
+import java.util.Locale;
+
+/**
+ * @author xagnetti
+ */
+public class FlexFilter implements FilenameFilter {
+ /*
+ * (non-Javadoc)
+ * @see java.io.FilenameFilter#accept(java.io.File, java.lang.String)
+ */
+ public boolean accept(final File dir,
+ final String name) {
+ boolean accepted = false;
+
+ if (!new File(dir, name).isDirectory()) {
+ accepted = name.toLowerCase(Locale.US).endsWith(".as")
+ || name.toLowerCase(Locale.US).endsWith(".mxml");
+ }
+ return accepted;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/utils/src/main/java/org/apache/flex/pmd/utils/RegexUtils.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/utils/src/main/java/org/apache/flex/pmd/utils/RegexUtils.java b/FlexPMD/language-module/utils/src/main/java/org/apache/flex/pmd/utils/RegexUtils.java
new file mode 100644
index 0000000..c00436f
--- /dev/null
+++ b/FlexPMD/language-module/utils/src/main/java/org/apache/flex/pmd/utils/RegexUtils.java
@@ -0,0 +1,16 @@
+package org.apache.flex.pmd.utils;
+
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.regex.Pattern;
+
+/**
+ * Created by christoferdutz on 06.03.15.
+ */
+public final class RegexUtils {
+
+ public static boolean isMatch(Pattern pattern, String input) {
+ return ((pattern != null) && StringUtils.isNotBlank(input)) && pattern.matcher(input).find();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/utils/src/main/java/org/apache/flex/pmd/utils/StackTraceUtils.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/utils/src/main/java/org/apache/flex/pmd/utils/StackTraceUtils.java b/FlexPMD/language-module/utils/src/main/java/org/apache/flex/pmd/utils/StackTraceUtils.java
new file mode 100644
index 0000000..708b4a9
--- /dev/null
+++ b/FlexPMD/language-module/utils/src/main/java/org/apache/flex/pmd/utils/StackTraceUtils.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 org.apache.flex.pmd.utils;
+
+/**
+ * @author xagnetti
+ */
+public final class StackTraceUtils {
+ /**
+ * Pretty print the first two lines of the stacktrace of the given exception
+ *
+ * @param exception Exception to print
+ * @return The first two lines of the stacktrace
+ */
+ public static String print(final Exception exception) {
+ return (exception.getMessage()
+ + " at " + exception.getStackTrace()[0] + "\n") + exception.getStackTrace()[1]
+ + "\n" + exception.getStackTrace()[2];
+ }
+
+ /**
+ * Pretty print the first two lines of the stacktrace of the given exception,
+ * specifying which file the exception was thrown on.
+ *
+ * @param fileName current fileName
+ * @param exception exception thrown
+ * @return error message
+ */
+ public static String print(final String fileName,
+ final Exception exception) {
+ return "on "
+ + fileName + " " + print(exception);
+ }
+
+ private StackTraceUtils() {
+ }
+}
[02/24] git commit: [flex-utilities]
[refs/heads/feature/pmd-5.2-language-module] - Initial commit of the PMD
language module for Apache Flex
Posted by cd...@apache.org.
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/event/FirstCustomEvent.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/event/FirstCustomEvent.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/event/FirstCustomEvent.as
new file mode 100644
index 0000000..ff58ac3
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/event/FirstCustomEvent.as
@@ -0,0 +1,30 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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
+{
+ public class FirstCustomEvent extends Event
+ {
+ public var lala : String;
+
+ public function FirstCustomEvent()
+ {
+
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/event/SecondCustomEvent.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/event/SecondCustomEvent.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/event/SecondCustomEvent.as
new file mode 100644
index 0000000..4628a40
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/event/SecondCustomEvent.as
@@ -0,0 +1,28 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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
+{
+ public class SecondCustomEvent extends CairngormEvent
+ {
+ public function SecondCustomEvent()
+ {
+ super("myDomain.SecondCustomEvent");
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/mxml/IterationsList.mxml
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/mxml/IterationsList.mxml b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/mxml/IterationsList.mxml
new file mode 100644
index 0000000..fa4e297
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/mxml/IterationsList.mxml
@@ -0,0 +1,90 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+
+ 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.
+
+-->
+<component:ScrawlGrid xmlns:mx="http://www.adobe.com/2006/mxml"
+ xmlns:component="com.adobe.ac.anthology.utils.components.*">
+ <!--
+ lalala
+ -->
+ <mx:Script>
+ <![CDATA[
+ import com.adobe.ac.anthology.model.object.IterationModelLocator;
+
+ import mx.collections.ArrayCollection;
+
+ public var lala : int = 1;
+ public var toto : int = 2;
+
+ private var _selectedIteration : Iteration;
+
+ public function set selectedIteration(value : Iteration) : void
+ {
+ for (var i : uint = 0; i < (dataProvider as ArrayCollection).length; i++) {
+ var currentId : uint = dataProvider[i].id;
+ if (currentId == value.id) {
+ selectedItem = dataProvider[i];
+ return;
+ }
+ }
+ }
+
+ public function set selectedIteration(value : Iteration) : void
+ {
+ for (var i : uint = 0; i < (dataProvider as ArrayCollection).length; i++) {
+ var currentId : uint = dataProvider[i].id;
+ if (currentId == value.id) {
+ selectedItem = dataProvider[i];
+ return;
+ }
+ }
+ }
+
+
+ public function set selectedIteration(value : Iteration) : void
+ {
+ for (var i : uint = 0; i < (dataProvider as ArrayCollection).length; i++) {
+ var currentId : uint = dataProvider[i].id;
+ if (currentId == value.id) {
+ selectedItem = dataProvider[i];
+ return;
+ }
+ }
+ }
+
+ private function displayTitle(item : Object, column : DataGridColumn) : String // No PMD UseObjectTypeRule
+ {
+ var i : Iteration = Iteration( item ); // NO PMD
+
+ return "#" + i.iterationNumber.toString() + " " + i.status;
+ }
+
+ public function get modelLocator() : FlexUnitLabelsModelLocator
+ {
+ return FlexUnitLabelsModelLocator.instance;
+ }
+ ]]>
+ </mx:Script>
+
+ <component:columns>
+
+ <mx:DataGridColumn dataField="iterationNumber" headerText="{ lala.lala }" labelFunction="displayTitle"/>
+
+ </component:columns>
+
+</component:ScrawlGrid>
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/mxml/IterationsList2.mxml
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/mxml/IterationsList2.mxml b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/mxml/IterationsList2.mxml
new file mode 100644
index 0000000..ec09be3
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/mxml/IterationsList2.mxml
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+
+ 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.
+
+-->
+<component:ScrawlGrid xmlns:mx="http://www.adobe.com/2006/mxml"
+ xmlns:component="com.adobe.ac.anthology.utils.components.*" text="{ vfrfr.frfr.frf }">
+ <!--
+ lalala
+ -->
+ <mx:Script>
+ <![CDATA[
+ import com.adobe.ac.anthology.model.object.Iteration;
+
+ import mx.collections.ArrayCollection;
+
+ public var lala : int = 1;
+
+ private var _selectedIteration : Iteration;
+ public static function myInit() : void {}
+ ]]>
+ </mx:Script>
+
+ <component:columns>
+
+ <mx:DataGridColumn dataField="iterationNumber" headerText="Iterations" labelFunction="displayTitle" text="{ vfrfr.frfr.frf.lala }"/>
+
+ </component:columns>
+
+</component:ScrawlGrid>
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/mxml/NestedComponent.mxml
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/mxml/NestedComponent.mxml b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/mxml/NestedComponent.mxml
new file mode 100644
index 0000000..8b4de62
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/mxml/NestedComponent.mxml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+
+ 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.
+
+-->
+<component:ScrawlGrid xmlns:mx="http://www.adobe.com/2006/mxml"
+ xmlns:component="com.adobe.ac.anthology.utils.components.*">
+
+ <mx:VBox>
+
+ <mx:HBox>
+
+ <mx:Panel>
+
+ </mx:Panel>
+
+ </mx:HBox>
+
+ <mx:Canvas>
+
+ <Accordeon>
+
+ </Accordeon>
+
+ </mx:Canvas>
+
+ </mx:VBox>
+
+</component:ScrawlGrid>
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/cairngorm/work/SequenceWorkFlow.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/cairngorm/work/SequenceWorkFlow.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/cairngorm/work/SequenceWorkFlow.as
new file mode 100644
index 0000000..a26ed35
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/cairngorm/work/SequenceWorkFlow.as
@@ -0,0 +1,19 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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.cairngorm.work
{
import mx.logging.ILogger;
import mx.logging.Log;
/**
* A work-flow that processes its children in sequence. The next child is
* started only when the previous child completes.
*/
public class SequenceWorkFlow extends WorkFlow
{
//------------------------------------------------------------------------
//
// Constants
//
//------------------------------------------------------------------------
private static const LOG : ILogger =
Log.getLogger( "com.adobe.cairngorm.work.SequenceWorkFlow" );
//------------------------------------------------------------------------
//
// Private Variables
//
//------------------------------------------------------------------------
/** The index of the work-item currently processing. */
private var currentIndex : uint = 0;
//----------------------------------------------
--------------------------
//
// Constructor
//
//------------------------------------------------------------------------
public function SequenceWorkFlow()
{
super();
}
//------------------------------------------------------------------------
//
// Implementation : WorkItem
//
//------------------------------------------------------------------------
override protected function performWork() : void
{
if ( Log.isDebug() )
{
LOG.debug(
"Starting sequence work-flow: label={0}, children={1}, size={2}",
label,
children.length,
size );
}
startNextWorkItem();
}
//------------------------------------------------------------------------
//
// Overrides : WorkFlow
//
//-----------------------------------------------------------------
-------
override protected function onChildWorkComplete( event : WorkEvent ) : void
{
super.onChildWorkComplete( event );
startNextWorkItem();
}
override protected function onChildWorkFault( event : WorkEvent ) : void
{
super.onChildWorkFault( event );
if ( Log.isError() )
{
LOG.error( "Fault during sequence work-flow: label={0}", label );
}
fault( event.message );
}
//------------------------------------------------------------------------
//
// Private methods
//
//------------------------------------------------------------------------
private function startNextWorkItem() : void
{
if ( hasMoreWorkItems )
{
final var skipped : Boolean = processChild( getNextChild() ) == false;
if ( skipped )
{
startNextWorkItem();
}
}
else
{
if ( Log.isDebug() )
{
LOG.debug( "Completed sequence work-flow: label={0}", label );
}
complete();
}
}
private function get hasMoreWorkItems() : Boolean
{
return children && currentIndex < children.length;
}
private function getNextChild() : IWorkItem
{
return children[ currentIndex++ ] as IWorkItem;
}
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/empty/Empty.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/empty/Empty.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/empty/Empty.as
new file mode 100644
index 0000000..0c6fb82
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/empty/Empty.as
@@ -0,0 +1,18 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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.
+//
+////////////////////////////////////////////////////////////////////////////////
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/empty/Empty.mxml
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/empty/Empty.mxml b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/empty/Empty.mxml
new file mode 100644
index 0000000..2f32d30
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/empty/Empty.mxml
@@ -0,0 +1,18 @@
+<!--
+
+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.
+
+-->
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/filters/MyPopup.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/filters/MyPopup.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/filters/MyPopup.as
new file mode 100644
index 0000000..a48f4e0
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/filters/MyPopup.as
@@ -0,0 +1,28 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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
+{
+ public class MyPopup extends Canvas
+ {
+ public function MyPopup()
+ {
+ filters = [ new DropShadowFilter() ];
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/filters/MyPopup.mxml
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/filters/MyPopup.mxml b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/filters/MyPopup.mxml
new file mode 100644
index 0000000..40ad830
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/filters/MyPopup.mxml
@@ -0,0 +1,32 @@
+<!--
+
+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.
+
+-->
+<mx:Canvas
+ xmlns:mx="http://www.adobe.com/2006/mxml"
+ xmlns:view="com.view.core.gui.*"
+ showFlexChrome="false"
+ layout="absolute"
+ height="768" width="1024"
+ applicationComplete="facade.startup(this)"
+ creationComplete="currentState='defaultLoginWindowState'"
+ filters="{ [ new DropShadowFilter() ]}"
+ >
+ <mx:filters>
+ <mx:DropShadowFilter/>
+ </mx:filters>
+</mx:Canvas>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/flexpmd114/a/Test.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/flexpmd114/a/Test.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/flexpmd114/a/Test.as
new file mode 100644
index 0000000..b0007b9
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/flexpmd114/a/Test.as
@@ -0,0 +1,39 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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 a
+{
+ import mx.controls.Alert;
+
+ public class Test
+ {
+ public function Test()
+ {
+ }
+
+ public function alert():void {
+ var o:Object = new Object();
+ Alert.show("A");
+ function localFunction(): void {}
+ var functionVarFunction:Function = function(): void { }
+
+ functionVarFunction();
+ }
+
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/flexpmd114/b/Test.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/flexpmd114/b/Test.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/flexpmd114/b/Test.as
new file mode 100644
index 0000000..161bef8
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/flexpmd114/b/Test.as
@@ -0,0 +1,35 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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 b
+{
+ import mx.controls.Alert;
+
+ public class Test
+ {
+ public function Test()
+ {
+ }
+
+ public function alert():void {
+ var o:Object = new Object();
+ Alert.show("B");
+ }
+
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/flexpmd114/c/Test.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/flexpmd114/c/Test.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/flexpmd114/c/Test.as
new file mode 100644
index 0000000..0bba9e8
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/flexpmd114/c/Test.as
@@ -0,0 +1,35 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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 c
+{
+ import mx.controls.Alert;
+
+ public class Test
+ {
+ public function Test()
+ {
+ }
+
+ public function alert():void {
+ var o:Object = new Object();
+ Alert.show("C");
+ }
+
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/flexunit/RaoulTest.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/flexunit/RaoulTest.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/flexunit/RaoulTest.as
new file mode 100644
index 0000000..2606372
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/flexunit/RaoulTest.as
@@ -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 suite.cases
+{
+ import flexunit.framework.TestCase;
+
+ import math.RaoulUtil;
+
+ public class RaoulTest
+ {
+ private var classToTestRef : math.RaoulUtil;
+ private static var _allowEdit : ArrayCollection = new ArrayCollection( [ COMMENT_ADDED, COMMENT_UPDATED ] );
+
+ private static var _locked : Boolean;
+ {
+ loacked = true;
+ }
+
+ [Before]
+ public function setUp() : void
+ {
+ classToTestRef = new RaoulUtil();
+ }
+
+ [Test]
+ public function foo() : void
+ {
+ classToTestRef.foo1();
+ }
+
+ [Test]
+ public function fooAgain() : void
+ {
+ classToTestRef.foo();
+ }
+
+ public static function editAllowed( status : ActionItemCommentStatus ) : Boolean
+ {
+ return _allowEdit.contains( status );
+ }
+
+ /** Locked constructor will fail if used outside of the enum class */
+ public function RaoulTest( key : int, name : String )
+ {
+ if ( _locked )
+ {
+ throw new Error( "Enumeration constructor is private, do not use externally" );
+ }
+ _key = key;
+ _name = name;
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/flexunit/RulesetTest.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/flexunit/RulesetTest.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/flexunit/RulesetTest.as
new file mode 100644
index 0000000..fc6819b
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/flexunit/RulesetTest.as
@@ -0,0 +1,62 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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.model
+{
+ import com.adobe.ac.pmd.control.events.GetRulesetContentEvent;
+ import com.adobe.ac.pmd.model.events.RulesetReceivedEvent;
+
+ import flexunit.framework.CairngormEventSource;
+ import flexunit.framework.EventfulTestCase;
+
+ import mx.collections.ArrayCollection;
+
+ public class RulesetTest extends EventfulTestCase
+ {
+ override public function setUp():void
+ {
+ model = new Ruleset();
+ }
+
+ public function testGetRulesetContent() : void
+ {
+ model.getRulesetContent( "ref" );
+ }
+
+ public function testOnReceiveRulesetContent() : void
+ {
+ var receivedRuleset : Ruleset = new Ruleset();
+
+ listenForEvent( model, RulesetReceivedEvent.EVENT_NAME );
+
+ receivedRuleset.name = "name";
+ receivedRuleset.description = "description";
+ receivedRuleset.rules = new ArrayCollection();
+ receivedRuleset.rulesets = new ArrayCollection();
+
+ model.onReceiveRulesetContent( receivedRuleset );
+
+ assertEvents();
+ assertEquals( model, RulesetReceivedEvent( lastDispatchedExpectedEvent ).ruleset );
+ assertEquals( receivedRuleset.name, model.name );
+ assertEquals( receivedRuleset.description, model.description );
+ assertEquals( receivedRuleset.rules, model.rules );
+ assertEquals( receivedRuleset.rulesets, model.rulesets );
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/fu/main/flex/Main.mxml
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/fu/main/flex/Main.mxml b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/fu/main/flex/Main.mxml
new file mode 100644
index 0000000..c98afcc
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/fu/main/flex/Main.mxml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+
+ 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.
+
+-->
+<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
+ <mx:Text text="Hello World!"/>
+</mx:Application>
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/fu/main/flex/TestRunnerApplication.mxml
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/fu/main/flex/TestRunnerApplication.mxml b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/fu/main/flex/TestRunnerApplication.mxml
new file mode 100644
index 0000000..a1fe0eb
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/fu/main/flex/TestRunnerApplication.mxml
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+
+ 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.
+
+-->
+<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
+ xmlns:mx="library://ns.adobe.com/flex/halo"
+ xmlns:s="library://ns.adobe.com/flex/spark" minHeight="768" minWidth="1024"
+ creationComplete="runTests()">
+ <s:layout>
+ <s:BasicLayout/>
+ </s:layout>
+
+ <fx:Script>
+ <![CDATA[
+ import org.sonatype.flexmojos.unitestingsupport.ControlSocket;
+ import org.sonatype.flexmojos.unitestingsupport.SocketReporter;
+
+
+ private var suites:Array = [MySuite];
+
+ private static var socketReporter:SocketReporter = SocketReporter.getInstance();
+
+ private static var controlSocket:ControlSocket = ControlSocket.getInstance();
+
+ private function runTests():void
+ {
+ socketReporter.port = 13539;
+ controlSocket.port = 13540;
+ controlSocket.connect();
+ socketReporter.runTests(suites);
+ }
+ ]]>
+ </fx:Script>
+
+</s:Application>
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/fu/test/flex/MySuite.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/fu/test/flex/MySuite.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/fu/test/flex/MySuite.as
new file mode 100644
index 0000000..f9e8b46
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/fu/test/flex/MySuite.as
@@ -0,0 +1,26 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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
+{
+ [Suite]
+ [RunWith("org.flexunit.runners.Suite")]
+ public class MySuite {
+ public var myTest:MyTest;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/fu/test/flex/MyTest.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/fu/test/flex/MyTest.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/fu/test/flex/MyTest.as
new file mode 100644
index 0000000..fcff4db
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/fu/test/flex/MyTest.as
@@ -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
+{
+ import org.flexunit.assertThat;
+
+ public class MyTest {
+
+ [Test]
+ public function dummyTest():void
+ {
+ assertThat(true);
+ }
+
+ private static var eventDispatcher:EventDispatcher = new EventDispatcher();
+
+ [Test(async)]
+ public function dummyTestFlexPMD132Async():void
+ {
+ Async.handleEvent(this, eventDispatcher, "myEvent", eventHandler);
+ eventDispatcher.dispatchEvent(new Event("myEvent")); // NO PMD DispatchHardCodedEventName
+ }
+
+ private function eventHandler(event:Event, ptd:*):void // NO PMD UnusedParameter,UseGenericType
+ {
+ Assert.assertTrue(true);
+ }
+
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/functional/FunctionalClient.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/functional/FunctionalClient.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/functional/FunctionalClient.as
new file mode 100644
index 0000000..df50a14
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/functional/FunctionalClient.as
@@ -0,0 +1,29 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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 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
+ {
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/functional/func1/api/Func1ExposedClass.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/functional/func1/api/Func1ExposedClass.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/functional/func1/api/Func1ExposedClass.as
new file mode 100644
index 0000000..6461d6e
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/functional/func1/api/Func1ExposedClass.as
@@ -0,0 +1,29 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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 functional.func1.api
+
+{
+ import functional.func1.restricted.Func1RestrictedClass;
+ import functional.func2.api.Func2ExposedClass;
+ import functional.func2.restricted.Func2RestrictedClass; // VIOLATION
+
+ public class Func1ExposedClass
+ {
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/functional/func1/restricted/Func1RestrictedClass.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/functional/func1/restricted/Func1RestrictedClass.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/functional/func1/restricted/Func1RestrictedClass.as
new file mode 100644
index 0000000..9ad7ba2
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/functional/func1/restricted/Func1RestrictedClass.as
@@ -0,0 +1,29 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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 functional.func1.restricted
+{
+ import functional.func1.api.Func1ExposedClass;
+ import functional.func2.api.Func2ExposedClass;
+ import functional.func2.restricted.Func2RestrictedClass; // VIOLATION
+
+ public class Func1RestrictedClass extends EventDispatcher
+ {
+ public var publicVar : Boolan;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/functional/func2/api/Func2ExposedClass.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/functional/func2/api/Func2ExposedClass.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/functional/func2/api/Func2ExposedClass.as
new file mode 100644
index 0000000..2a2f5d4
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/functional/func2/api/Func2ExposedClass.as
@@ -0,0 +1,28 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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 functional.func2.api
+{
+ import functional.func1.api.Func1ExposedClass;
+ import functional.func1.restricted.Func1RestrictedClass; // VIOLATION
+ import functional.func2.restricted.Func2RestrictedClass;
+
+ public class Func2ExposedClass
+ {
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/functional/func2/restricted/Func2RestrictedClass.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/functional/func2/restricted/Func2RestrictedClass.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/functional/func2/restricted/Func2RestrictedClass.as
new file mode 100644
index 0000000..73f1789
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/functional/func2/restricted/Func2RestrictedClass.as
@@ -0,0 +1,28 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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 functional.func2.restricted
+{
+ import functional.func1.api.Func1ExposedClass;
+ import functional.func1.restricted.Func1RestrictedClass; // VIOLATION
+ import functional.func2.api.Func2ExposedClass;
+
+ public class Func2RestrictedClass
+ {
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/mx/controls/DateChooser2.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/mx/controls/DateChooser2.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/mx/controls/DateChooser2.as
new file mode 100644
index 0000000..8900d5b
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/mx/controls/DateChooser2.as
@@ -0,0 +1,25 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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 mx.controls
+{
+ public class DateChooser extends UIComponent implements IFocusManagerComponent, IFontContextComponent
+ {
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/org/as3commons/concurrency/thread/Color.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/org/as3commons/concurrency/thread/Color.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/org/as3commons/concurrency/thread/Color.as
new file mode 100644
index 0000000..9265cf3
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/org/as3commons/concurrency/thread/Color.as
@@ -0,0 +1,25 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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 org.as3commons.concurrency.threads
+{
+ public interface Color
+ {
+ function foo() : void;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/parsley/InaccessibleMetaData.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/parsley/InaccessibleMetaData.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/parsley/InaccessibleMetaData.as
new file mode 100644
index 0000000..307ab35
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/parsley/InaccessibleMetaData.as
@@ -0,0 +1,53 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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 parsley
+{
+ [Event(name="message", type="flash.events.Event")]
+ public class InaccessibleMetaData
+ {
+ public var publicVar;
+
+ [Inject] // VIOLATION
+ private var privateVar : String;
+
+ [Inject]
+ public function set publicSetter( value : String ) : void
+ {
+ privateSetter = value;
+ }
+
+ [Inject] // VIOLATION
+ private function set privateSetter( value : String ) : void
+ {
+ publicVar = value;
+ }
+
+ [MessageHandler]
+ public function publicFunction( event : MyEvent ) : void
+ {
+ privateFunction( event );
+ }
+
+ [MessageHandler] // VIOLATION
+ private function privateFunction( event : MyEvent ) : void
+ {
+ privateVar = event.toString();
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/parsley/InaccessibleMetaDataInternalClass.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/parsley/InaccessibleMetaDataInternalClass.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/parsley/InaccessibleMetaDataInternalClass.as
new file mode 100644
index 0000000..e05cd20
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/parsley/InaccessibleMetaDataInternalClass.as
@@ -0,0 +1,25 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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 parsley
+{
+ [AsyncInit]
+ internal class InaccessibleMetaDataInternalClass
+ {
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/parsley/MessageInterceptorSignature.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/parsley/MessageInterceptorSignature.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/parsley/MessageInterceptorSignature.as
new file mode 100644
index 0000000..2cac794
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/parsley/MessageInterceptorSignature.as
@@ -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 parsley
+{
+ public class MessageInterceptorSignature
+ {
+ [MessageInterceptor(type="a.b.MyMessage")]
+ public function messageInterceptor( processor : MessageProcessor ) : void
+ {
+ processor.proceed();
+ }
+
+ [MessageInterceptor(type="a.b.MyMessage")]
+ public function messageInterceptor() : void // VIOLATION
+ {
+ }
+
+ [MessageInterceptor(type="a.b.MyMessage")]
+ public function messageInterceptor( type : MyMessage ) : void // VIOLATION
+ {
+ type.something();
+ }
+
+ [MessageInterceptor(type="a.b.MyMessage")]
+ public function messageInterceptor( processor : MessageProcessor, type : MyMessage ) : void // VIOLATION
+ {
+ processor.proceed();
+ type.something();
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/parsley/MismatchedManagedEvent.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/parsley/MismatchedManagedEvent.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/parsley/MismatchedManagedEvent.as
new file mode 100644
index 0000000..d5af8df
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/parsley/MismatchedManagedEvent.as
@@ -0,0 +1,28 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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 parsley
+{
+ [Event(name="messageA", type="flash.events.Event")]
+ [Event(name="messageB", type="flash.events.Event")]
+ [ManagedEvents(names="messageA,messageB")]
+ [ManagedEvents(names="messageC")] // VIOLATION
+ public class MismatchedManagedEvent
+ {
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/parsley/MisplacedMetaData.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/parsley/MisplacedMetaData.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/parsley/MisplacedMetaData.as
new file mode 100644
index 0000000..71c1e2c
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/parsley/MisplacedMetaData.as
@@ -0,0 +1,65 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package parsley
+{
+ [Inject] // VIOLATION
+ [MessageBinding(type="a.b.MyMessage", messageProperty="a")] // VIOLATION
+ [MessageDispatcher] // VIOLATION
+ [MessageError] // VIOLATION
+ [MessageHandler] // VIOLATION
+ [MessageInterceptor] // VIOLATION
+ [Init] // VIOLATION
+ [Destroy] // VIOLATION
+ [ResourceBinding(key="a")] // VIOLATION
+ [Factory] // VIOLATION
+ [ObjectDefinition] // VIOLATION
+ [Target] // VIOLATION
+ [Internal] // VIOLATION
+ public class MisplacedMetaData
+ {
+ [InjectConstructor] // VIOLATION
+ [ManagedEvents(names="a")] // VIOLATION
+ [MessageError] // VIOLATION
+ [MessageHandler] // VIOLATION
+ [MessageInterceptor] // VIOLATION
+ [Init] // VIOLATION
+ [Destroy] // VIOLATION
+ [Factory] // VIOLATION
+ public var property : String;
+
+ [InjectConstructor] // VIOLATION
+ public function MisplacedMetaData()
+ {
+ }
+
+ [ManagedEvents(names="a")] // VIOLATION
+ [MessageBinding(type="a.b.MyMessage", messageProperty="a")] // VIOLATION
+ [MessageDispatcher] // VIOLATION
+ [AsyncInit] // VIOLATION
+ [ResourceBinding(key="a")] // VIOLATION
+ [ObjectDefinition] // VIOLATION
+ [Target] // VIOLATION
+ [Internal] // VIOLATION
+ public function doSomething( message : MyMessage ) : void
+ {
+ message.toString();
+ property.toString();
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/parsley/RedundantMessageHandlerTypeAttribute.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/parsley/RedundantMessageHandlerTypeAttribute.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/parsley/RedundantMessageHandlerTypeAttribute.as
new file mode 100644
index 0000000..c67f3a8
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/parsley/RedundantMessageHandlerTypeAttribute.as
@@ -0,0 +1,35 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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 parsley
+{
+ public class RedundantMessageHandlerTypeAttribute
+ {
+ [MessageHandler]
+ public function doSomething( message : MyMessage ) : void
+ {
+ message.toString();
+ }
+
+ [MessageHandler(type="a.b.MyMessage")] // VIOLATION
+ public function doSomething( message : MyMessage ) : void
+ {
+ message.toString();
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/parsley/RedundantMethodAttribute.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/parsley/RedundantMethodAttribute.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/parsley/RedundantMethodAttribute.as
new file mode 100644
index 0000000..76cfecb
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/parsley/RedundantMethodAttribute.as
@@ -0,0 +1,35 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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 parsley
+{
+ public class RedundantMethodAttribute
+ {
+ [MessageHandler]
+ public function doSomething( message : MyMessage ) : void
+ {
+ message.toString();
+ }
+
+ [MessageHandler(method="doSomething")] // VIOLATION
+ public function doSomething( message : MyMessage ) : void
+ {
+ message.toString();
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/parsley/UnknownMetaDataAttribute.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/parsley/UnknownMetaDataAttribute.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/parsley/UnknownMetaDataAttribute.as
new file mode 100644
index 0000000..05b9be4
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/parsley/UnknownMetaDataAttribute.as
@@ -0,0 +1,32 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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 parsley
+{
+ [AsyncInit(x="y")] // VIOLATION
+ public class UnknownMetaDataAttribute
+ {
+ [Inject(x="y")] // VIOLATION
+ public var inject;
+
+ [MessageHandler(x="y")] // VIOLATION
+ public function messageHandler() : void
+ {
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/pseudo/look/IEditLook.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/pseudo/look/IEditLook.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/pseudo/look/IEditLook.as
new file mode 100644
index 0000000..67bc669
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/pseudo/look/IEditLook.as
@@ -0,0 +1,24 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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.
+//
+////////////////////////////////////////////////////////////////////////////////
+
+interface pseudo.look.IEditLook extends pseudo.look.IBaseLook
+{
+ public function getTextFormat(data:Object):TextFormat;
+ public function getTextDecoration(strType:String, data:Object):String;
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/schedule_internal.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/schedule_internal.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/schedule_internal.as
new file mode 100644
index 0000000..74e0e76
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/schedule_internal.as
@@ -0,0 +1,22 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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 flexlib.scheduling.scheduleClasses
+{
+ public namespace schedule_internal = "http://www.adobe.com/ac/scheduling/internal";
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/src/fw/data/request/ResultListener.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/src/fw/data/request/ResultListener.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/src/fw/data/request/ResultListener.as
new file mode 100644
index 0000000..90d768a
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/src/fw/data/request/ResultListener.as
@@ -0,0 +1,27 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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.
+//
+////////////////////////////////////////////////////////////////////////////////
+
+import src.fw.data.request.Request;
+interface src.fw.data.request.ResultListener
+{
+ public function onResultLoad(request:Request) : Void;
+
+ public function onResultError(request:Request) : Void;
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/utils/pom.xml
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/utils/pom.xml b/FlexPMD/language-module/utils/pom.xml
new file mode 100644
index 0000000..a753d1d
--- /dev/null
+++ b/FlexPMD/language-module/utils/pom.xml
@@ -0,0 +1,42 @@
+<!--
+
+ 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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.flex.pmd</groupId>
+ <artifactId>apache-flex-pmd</artifactId>
+ <version>2.0.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>utils</artifactId>
+ <version>2.0.0-SNAPSHOT</version>
+ <packaging>jar</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ <version>${commons-lang.version}</version>
+ </dependency>
+ </dependencies>
+
+</project>
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/utils/src/main/java/org/apache/flex/pmd/utils/FileUtils.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/utils/src/main/java/org/apache/flex/pmd/utils/FileUtils.java b/FlexPMD/language-module/utils/src/main/java/org/apache/flex/pmd/utils/FileUtils.java
new file mode 100644
index 0000000..2c7346b
--- /dev/null
+++ b/FlexPMD/language-module/utils/src/main/java/org/apache/flex/pmd/utils/FileUtils.java
@@ -0,0 +1,164 @@
+/*
+ * 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 org.apache.flex.pmd.utils;
+
+import java.io.*;
+import java.util.*;
+
+/**
+ * @author xagnetti
+ */
+public final class FileUtils {
+ public static class FilePathComparator implements Comparator<File> {
+ public int compare(final File arg0,
+ final File arg1) {
+ return arg0.getAbsolutePath().compareTo(arg1.getAbsolutePath());
+ }
+ }
+
+ /**
+ * @param line
+ * @return
+ */
+ public static boolean isLineACorrectStatement(final String line) {
+ return line.compareTo("") != 0
+ && lrtrim(line).compareTo("{") != 0 && lrtrim(line).compareTo("}") != 0
+ && line.endsWith(";");
+ }
+
+ /**
+ * @param directory
+ * @param filter
+ * @param recurse
+ * @return
+ */
+ public static Collection<File> listFiles(final File directory,
+ final FilenameFilter filter,
+ final boolean recurse) {
+ final ArrayList<File> files = listFilesRecurse(directory,
+ filter,
+ recurse);
+ Collections.sort(files,
+ new FilePathComparator());
+ return files;
+ }
+
+ /**
+ * @param sourceDirectory
+ * @param filter
+ * @param recurse
+ * @return
+ */
+ public static Collection<File> listFiles(final List<File> sourceDirectory,
+ final FilenameFilter filter,
+ final boolean recurse) {
+ final ArrayList<File> files = new ArrayList<File>();
+
+ for (final File topDirectory : sourceDirectory) {
+ files.addAll(listFilesRecurse(topDirectory,
+ filter,
+ recurse));
+ }
+
+ Collections.sort(files,
+ new FilePathComparator());
+ return files;
+ }
+
+ /**
+ * @param file
+ * @return
+ */
+ public static List<String> readFile(final File file) {
+ final List<String> result = new ArrayList<String>();
+
+ BufferedReader inReader = null;
+ try {
+ final Reader reader = new InputStreamReader(new FileInputStream(file), "UTF-8");
+ inReader = new BufferedReader(reader);
+
+ String line = readLine(inReader);
+
+ while (line != null) {
+ result.add(line);
+ line = readLine(inReader);
+ }
+ inReader.close();
+ } catch (final IOException e) {
+ StackTraceUtils.print(e);
+ }
+ return result;
+ }
+
+ private static ArrayList<File> listFilesRecurse(final File directory,
+ final FilenameFilter filter,
+ final boolean recurse) {
+ final ArrayList<File> files = new ArrayList<File>();
+ final File[] entries = directory.listFiles();
+
+ if (entries != null) {
+ for (final File entry : entries) {
+ if (filter == null
+ || filter.accept(directory,
+ entry.getName())) {
+ files.add(entry);
+ }
+ if (recurse
+ && entry.isDirectory()) {
+ files.addAll(listFilesRecurse(entry,
+ filter,
+ recurse));
+ }
+ }
+ }
+ return files;
+ }
+
+ private static String lrtrim(final String source) {
+ return ltrim(rtrim(source));
+ }
+
+ /* remove leading whitespace */
+ private static String ltrim(final String source) {
+ return source.replaceAll("^\\s+",
+ "");
+ }
+
+ public static String[] readLines(final File file) throws IOException {
+ List<String> lines = readFile(file);
+ return lines.toArray(new String[lines.size()]);
+ }
+
+ private static String readLine(final BufferedReader inReader) throws IOException {
+ final String line = inReader.readLine();
+
+ if (line != null) {
+ return line.replaceAll("\uFEFF",
+ "");
+ }
+ return null;
+ }
+
+ /* remove trailing whitespace */
+ private static String rtrim(final String source) {
+ return source.replaceAll("\\s+$",
+ "");
+ }
+
+ private FileUtils() {
+ }
+}
[04/24] git commit: [flex-utilities]
[refs/heads/feature/pmd-5.2-language-module] - Initial commit of the PMD
language module for Apache Flex
Posted by cd...@apache.org.
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/FlexPMD181.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/FlexPMD181.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/FlexPMD181.as
new file mode 100644
index 0000000..bd94928
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/FlexPMD181.as
@@ -0,0 +1,2344 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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 org.as3commons.lang {
+
+ /**
+ * <p>Methods in this class give sample code to explain their operation.
+ * The symbol <code>*</code> is used to indicate any input
+ * including <code>null</code>.</p>
+ *
+ * @author Steffen Leistner
+ * @author Christophe Herreman
+ */
+ public class StringUtils { // NO PMD TooManyFunction TooManyPublic
+
+ /**
+ * The empty String <code>""</code>
+ */
+ private static const EMPTY:String = '';
+
+ /**
+ * Represents a failed index search.
+ */
+ private static const INDEX_NOT_FOUND:int = -1;
+
+ /**
+ * The control character code
+ */
+ private static const WHITE:uint = 32;
+
+ /**
+ * <p>The maximum size to which the padding constant(s) can expand.</p>
+ */
+ private static const PAD_LIMIT:uint = 8192;
+
+ /**
+ * <p>Returns a simple Initials like string.</p>
+ *
+ * StringUtils.toInitials("stringutils") = s
+ * StringUtils.toInitials("stringUtils") = su
+ * StringUtils.toInitials("stringUtilsTest") = sut
+ */
+ public static function toInitials(str:String):String {
+ if (isEmpty(str)) {
+ return str;
+ }
+ return str.match(/[A-Z]/g).join('').toLowerCase();
+ }
+
+ /**
+ * <p>Removes one newline from end of a String if it's there,
+ * otherwise leave it alone. A newline is "<code>\n</code>",
+ * "<code>\r</code>", or "<code>\r\n</code>".</p>
+ *
+ * <pre>
+ * StringUtils.chomp(null) = null
+ * StringUtils.chomp("") = ""
+ * StringUtils.chomp("abc \r") = "abc "
+ * StringUtils.chomp("abc\n") = "abc"
+ * StringUtils.chomp("abc\r\n") = "abc"
+ * StringUtils.chomp("abc\r\n\r\n") = "abc\r\n"
+ * StringUtils.chomp("abc\n\r") = "abc\n"
+ * StringUtils.chomp("abc\n\rabc") = "abc\n\rabc"
+ * StringUtils.chomp("\r") = ""
+ * StringUtils.chomp("\n") = ""
+ * StringUtils.chomp("\r\n") = ""
+ * </pre>
+ *
+ * @param str the String to chomp a newline from, may be null
+ * @return String without newline, <code>null</code> if null String input
+ */
+ public static function chomp(str:String):String {
+ return chompString(str, '(\r\n|\r|\n)');
+ }
+
+ /**
+ * <p>Removes <code>separator</code> from the end of
+ * <code>str</code> if it's there, otherwise leave it alone.</p>
+ *
+ * <p>It now more closely matches Perl chomp.
+ * For the previous behavior, use #substringBeforeLast(String, String).
+ * This method uses #endsWith(String).</p>
+ *
+ * <pre>
+ * StringUtils.chompString(null, *) = null
+ * StringUtils.chompString("", *) = ""
+ * StringUtils.chompString("foobar", "bar") = "foo"
+ * StringUtils.chompString("foobar", "baz") = "foobar"
+ * StringUtils.chompString("foo", "foo") = ""
+ * StringUtils.chompString("foo ", "foo") = "foo "
+ * StringUtils.chompString(" foo", "foo") = " "
+ * StringUtils.chompString("foo", "foooo") = "foo"
+ * StringUtils.chompString("foo", "") = "foo"
+ * StringUtils.chompString("foo", null) = "foo"
+ * </pre>
+ *
+ * @param str the String to chomp from, may be null
+ * @param separator separator String, may be null
+ * @return String without trailing separator, <code>null</code> if null String input
+ */
+ public static function chompString(str:String, separator:String):String {
+ if (isEmpty(str) || separator == null) {
+ return str;
+ }
+ return str.replace(new RegExp(separator + '$', ''), '')
+ }
+
+ /**
+ * <p>Removes control characters(char <= 32) from both
+ * ends of this String, handling <code>null</code> by returning
+ * <code>null</code>.</p>
+ *
+ * <p>Trim removes start and end characters <= 32.
+ * To strip whitespace use #strip(String).</p>
+ *
+ * <p>To trim your choice of characters, use the
+ * #strip(String, String) methods.</p>
+ *
+ * <pre>
+ * StringUtils.trim(null) = null
+ * StringUtils.trim("") = ""
+ * StringUtils.trim(" ") = ""
+ * StringUtils.trim("abc") = "abc"
+ * StringUtils.trim(" abc ") = "abc"
+ * </pre>
+ *
+ * @param str the String to be trimmed, may be null
+ * @return the trimmed string, <code>null</code> if null String input
+ */
+ public static function trim(str:String):String {
+ if (str == null) {
+ return null;
+ }
+ return str.replace(/^\s*/, '').replace(/\s*$/, '');
+ }
+
+ /**
+ * <p>Deletes all 'space' characters from a String as defined by
+ *
+ * <pre>
+ * StringUtils.deleteSpaces(null) = null
+ * StringUtils.deleteSpaces("") = ""
+ * StringUtils.deleteSpaces("abc") = "abc"
+ * StringUtils.deleteSpaces(" \tabc \n ") = " abc "
+ * StringUtils.deleteSpaces("a\nb\tc ") = "abc "
+ * </pre>
+ *
+ * <p>Spaces are defined as <code>{'\t', '\r', '\n', '\b'}</code>
+ * in line with the deprecated <code>isSpace</code> method.</p>
+ *
+ * @param str the String to delete spaces from, may be null
+ * @return the String without 'spaces', <code>null</code> if null String input
+ */
+ public static function deleteSpaces(str:String):String {
+ return deleteFromString(str, /\t|\r|\n|\b/g);
+ }
+
+ /**
+ * <p>Deletes all whitespaces from a String.</p>
+ *
+ * <pre>
+ * StringUtils.deleteWhitespace(null) = null
+ * StringUtils.deleteWhitespace("") = ""
+ * StringUtils.deleteWhitespace("abc") = "abc"
+ * StringUtils.deleteWhitespace(" ab c ") = "abc"
+ * </pre>
+ *
+ * @param str the String to delete whitespace from, may be null
+ * @return the String without whitespaces, <code>null</code> if null String input
+ */
+ public static function deleteWhitespace(str:String):String {
+ return deleteFromString(str, /\s/g);
+ }
+
+ private static function deleteFromString(str:String, pattern:RegExp):String {
+ if (isEmpty(str)) {
+ return str;
+ }
+ return str.replace(pattern, '');
+ }
+
+ /**
+ * <p>Gets the leftmost <code>len</code> characters of a String.</p>
+ *
+ * <p>If <code>len</code> characters are not available, or the
+ * String is <code>null</code>, the String will be returned without
+ * an exception. An exception is thrown if len is negative.</p>
+ *
+ * <pre>
+ * StringUtils.left(null, *) = null
+ * StringUtils.left(*, -ve) = ""
+ * StringUtils.left("", *) = ""
+ * StringUtils.left("abc", 0) = ""
+ * StringUtils.left("abc", 2) = "ab"
+ * StringUtils.left("abc", 4) = "abc"
+ * </pre>
+ *
+ * @param str the String to get the leftmost characters from, may be null
+ * @param len the length of the required String, must be zero or positive
+ * @return the leftmost characters, <code>null</code> if null String input
+ */
+ public static function left(str:String, len:int):String {
+ if (str == null) {
+ return null;
+ }
+
+ if (len < 0) {
+ return EMPTY;
+ }
+
+ if (str.length <= len) {
+ return str;
+ }
+ return str.substring(0, len);
+ }
+
+ /**
+ * <p>Centers a String in a larger String of size <code>size</code>.
+ * Uses a supplied String as the value to pad the String with.</p>
+ *
+ * <p>If the size is less than the String length, the String is returned.
+ * A <code>null</code> String returns <code>null</code>.
+ * A negative size is treated as zero.</p>
+ *
+ * <pre>
+ * StringUtils.center(null, *, *) = null
+ * StringUtils.center("", 4, " ") = " "
+ * StringUtils.center("ab", -1, " ") = "ab"
+ * StringUtils.center("ab", 4, " ") = " ab "
+ * StringUtils.center("abcd", 2, " ") = "abcd"
+ * StringUtils.center("a", 4, " ") = " a "
+ * StringUtils.center("a", 4, "yz") = "yayz"
+ * StringUtils.center("abc", 7, null) = " abc "
+ * StringUtils.center("abc", 7, "") = " abc "
+ * </pre>
+ *
+ * @param str the String to center, may be null
+ * @param size the int size of new String, negative treated as zero
+ * @param padStr the String to pad the new String with, must not be null or empty
+ * @return centered String, <code>null</code> if null String input
+ */
+ public static function center(str:String, size:int, padStr:String):String {
+ if (str == null || size <= 0) {
+ return str;
+ }
+
+ if (isEmpty(padStr)) {
+ padStr = " ";
+ }
+ var strLen:int = str.length;
+ var pads:int = size - strLen;
+
+ if (pads <= 0) {
+ return str;
+ }
+ str = leftPad(str, strLen + pads / 2, padStr);
+ str = rightPad(str, size, padStr);
+
+ return str;
+ }
+
+ /**
+ * <p>Left pad a String with a specified String.</p>
+ *
+ * <p>Pad to a size of <code>size</code>.</p>
+ *
+ * <pre>
+ * StringUtils.leftPad(null, *, *) = null
+ * StringUtils.leftPad("", 3, "z") = "zzz"
+ * StringUtils.leftPad("bat", 3, "yz") = "bat"
+ * StringUtils.leftPad("bat", 5, "yz") = "yzbat"
+ * StringUtils.leftPad("bat", 8, "yz") = "yzyzybat"
+ * StringUtils.leftPad("bat", 1, "yz") = "bat"
+ * StringUtils.leftPad("bat", -1, "yz") = "bat"
+ * StringUtils.leftPad("bat", 5, null) = " bat"
+ * StringUtils.leftPad("bat", 5, "") = " bat"
+ * </pre>
+ *
+ * @param str the String to pad out, may be null
+ * @param size the size to pad to
+ * @param padStr the String to pad with, null or empty treated as single space
+ * @return left padded String or original String if no padding is necessary,
+ * <code>null</code> if null String input
+ */
+ public static function leftPad(str:String, size:int, padStr:String):String {
+ if (str == null) {
+ return null;
+ }
+
+ if (isEmpty(padStr)) {
+ padStr = " ";
+ }
+ var padLen:int = padStr.length;
+ var strLen:int = str.length;
+ var pads:int = size - strLen;
+
+ if (pads <= 0) {
+ return str; // returns original String when possible
+ }
+
+ if (padLen == 1 && pads <= PAD_LIMIT) {
+ return leftPadChar(str, size, padStr.charAt(0));
+ }
+
+ if (pads == padLen) {
+ return padStr.concat(str);
+ } else if (pads < padLen) {
+ return padStr.substring(0, pads).concat(str);
+ } else {
+ var padding:Array = [];
+ var padChars:Array = padStr.split("");
+
+ for (var i:int = 0; i < pads; i++) {
+ padding[i] = padChars[i % padLen];
+ }
+ return padding.join("").concat(str);
+ }
+ }
+
+ /**
+ * <p>Left pad a String with a specified character.</p>
+ *
+ * <p>Pad to a size of <code>size</code>.</p>
+ *
+ * <pre>
+ * StringUtils.leftPadChar(null, *, *) = null
+ * StringUtils.leftPadChar("", 3, 'z') = "zzz"
+ * StringUtils.leftPadChar("bat", 3, 'z') = "bat"
+ * StringUtils.leftPadChar("bat", 5, 'z') = "zzbat"
+ * StringUtils.leftPadChar("bat", 1, 'z') = "bat"
+ * StringUtils.leftPadChar("bat", -1, 'z') = "bat"
+ * </pre>
+ *
+ * @param str the String to pad out, may be null
+ * @param size the size to pad to
+ * @param padChar the character to pad with
+ * @return left padded String or original String if no padding is necessary,
+ * <code>null</code> if null String input
+ */
+ public static function leftPadChar(str:String, size:int, padChar:String):String {
+ if (str == null) {
+ return null;
+ }
+ var pads:int = size - str.length;
+
+ if (pads <= 0) {
+ return str; // returns original String when possible
+ }
+
+ if (pads > PAD_LIMIT) {
+ return leftPad(str, size, padChar);
+ }
+ return padding(pads, padChar).concat(str);
+ }
+
+ /**
+ * <p>Right pad a String with a specified String.</p>
+ *
+ * <p>The String is padded to the size of <code>size</code>.</p>
+ *
+ * <pre>
+ * StringUtils.rightPad(null, *, *) = null
+ * StringUtils.rightPad("", 3, "z") = "zzz"
+ * StringUtils.rightPad("bat", 3, "yz") = "bat"
+ * StringUtils.rightPad("bat", 5, "yz") = "batyz"
+ * StringUtils.rightPad("bat", 8, "yz") = "batyzyzy"
+ * StringUtils.rightPad("bat", 1, "yz") = "bat"
+ * StringUtils.rightPad("bat", -1, "yz") = "bat"
+ * StringUtils.rightPad("bat", 5, null) = "bat "
+ * StringUtils.rightPad("bat", 5, "") = "bat "
+ * </pre>
+ *
+ * @param str the String to pad out, may be null
+ * @param size the size to pad to
+ * @param padStr the String to pad with, null or empty treated as single space
+ * @return right padded String or original String if no padding is necessary,
+ * <code>null</code> if null String input
+ */
+ public static function rightPad(str:String, size:int, padStr:String):String {
+ if (str == null) {
+ return null;
+ }
+
+ if (isEmpty(padStr)) {
+ padStr = " ";
+ }
+ var padLen:int = padStr.length;
+ var strLen:int = str.length;
+ var pads:int = size - strLen;
+
+ if (pads <= 0) {
+ return str; // returns original String when possible
+ }
+
+ if (padLen == 1 && pads <= PAD_LIMIT) {
+ return rightPadChar(str, size, padStr.charAt(0));
+ }
+
+ if (pads == padLen) {
+ return str.concat(padStr);
+ } else if (pads < padLen) {
+ return str.concat(padStr.substring(0, pads));
+ } else {
+ var padding:Array = [];
+ var padChars:Array = padStr.split("");
+
+ for (var i:int = 0; i < pads; i++) {
+ padding[i] = padChars[i % padLen];
+ }
+ return str.concat(padding.join(""));
+ }
+ }
+
+ /**
+ * <p>Right pad a String with a specified character.</p>
+ *
+ * <p>The String is padded to the size of <code>size</code>.</p>
+ *
+ * <pre>
+ * StringUtils.rightPadChar(null, *, *) = null
+ * StringUtils.rightPadChar("", 3, 'z') = "zzz"
+ * StringUtils.rightPadChar("bat", 3, 'z') = "bat"
+ * StringUtils.rightPadChar("bat", 5, 'z') = "batzz"
+ * StringUtils.rightPadChar("bat", 1, 'z') = "bat"
+ * StringUtils.rightPadChar("bat", -1, 'z') = "bat"
+ * </pre>
+ *
+ * @param str the String to pad out, may be null
+ * @param size the size to pad to
+ * @param padChar the character to pad with
+ * @return right padded String or original String if no padding is necessary,
+ * <code>null</code> if null String input
+ */
+ public static function rightPadChar(str:String, size:int, padChar:String):String {
+ if (str == null) {
+ return null;
+ }
+ var pads:int = size - str.length;
+
+ if (pads <= 0) {
+ return str; // returns original String when possible
+ }
+
+ if (pads > PAD_LIMIT) {
+ return rightPad(str, size, padChar);
+ }
+ return str.concat(padding(pads, padChar));
+ }
+
+ /**
+ * <p>Returns padding using the specified delimiter repeated
+ * to a given length.</p>
+ *
+ * <pre>
+ * StringUtils.padding(0, 'e') = ""
+ * StringUtils.padding(3, 'e') = "eee"
+ * StringUtils.padding(-2, 'e') = IndexOutOfBoundsException
+ * </pre>
+ *
+ * @param repeat number of times to repeat delim
+ * @param padChar character to repeat
+ * @return String with repeated character
+ */
+ private static function padding(repeat:int, padChar:String):String {
+ var buffer:String = '';
+
+ for (var i:int = 0; i < repeat; i++) {
+ buffer += padChar;
+ }
+ return buffer;
+ }
+
+ /**
+ * <p>Replaces all occurrences of a String within another String.</p>
+ *
+ * <p>A <code>null</code> reference passed to this method is a no-op.</p>
+ *
+ * <pre>
+ * StringUtils.replace(null, *, *) = null
+ * StringUtils.replace("", *, *) = ""
+ * StringUtils.replace("any", null, *) = "any"
+ * StringUtils.replace("any", *, null) = "any"
+ * StringUtils.replace("any", "", *) = "any"
+ * StringUtils.replace("aba", "a", null) = "aba"
+ * StringUtils.replace("aba", "a", "") = "b"
+ * StringUtils.replace("aba", "a", "z") = "zbz"
+ * </pre>
+ *
+ * @param text text to search and replace in, may be null
+ * @param pattern the String to search for, may be null
+ * @param repl the String to replace with, may be null
+ * @return the text with any replacements processed,
+ * <code>null</code> if null String input
+ */
+ public static function replace(text:String, pattern:String, repl:String):String {
+ if (text == null || isEmpty(pattern) || repl == null) {
+ return text;
+ }
+ return text.replace(new RegExp(pattern, 'g'), repl);
+ }
+
+ /**
+ * <p>Replaces a String with another String inside a larger String,
+ * for the first <code>max</code> values of the search String.</p>
+ *
+ * <p>A <code>null</code> reference passed to this method is a no-op.</p>
+ *
+ * <pre>
+ * StringUtils.replaceTo(null, *, *, *) = null
+ * StringUtils.replaceTo("", *, *, *) = ""
+ * StringUtils.replaceTo("any", null, *, *) = "any"
+ * StringUtils.replaceTo("any", *, null, *) = "any"
+ * StringUtils.replaceTo("any", "", *, *) = "any"
+ * StringUtils.replaceTo("any", *, *, 0) = "any"
+ * StringUtils.replaceTo("abaa", "a", null, -1) = "abaa"
+ * StringUtils.replaceTo("abaa", "a", "", -1) = "b"
+ * StringUtils.replaceTo("abaa", "a", "z", 0) = "abaa"
+ * StringUtils.replaceTo("abaa", "a", "z", 1) = "zbaa"
+ * StringUtils.replaceTo("abaa", "a", "z", 2) = "zbza"
+ * StringUtils.replaceTo("abaa", "a", "z", -1) = "zbzz"
+ * </pre>
+ *
+ * @param text text to search and replace in, may be null
+ * @param repl the String to search for, may be null
+ * @param with the String to replace with, may be null
+ * @param max maximum number of values to replace, or <code>-1</code> if no maximum
+ * @return the text with any replacements processed,
+ * <code>null</code> if null String input
+ */
+ public static function replaceTo(text:String, pattern:String, repl:String, max:int):String {
+ if (text == null || isEmpty(pattern) || repl == null || max == 0) {
+ return text;
+ }
+
+ var buf:String = "";
+ var start:int = 0;
+ var end:int = 0;
+
+ while ((end = text.indexOf(pattern, start)) != -1) {
+ buf += text.substring(start, end) + repl;
+ start = end + pattern.length;
+
+ if (--max == 0) {
+ break;
+ }
+ }
+ return buf += text.substring(start);
+ }
+
+ /**
+ * <p>Replaces a String with another String inside a larger String, once.</p>
+ *
+ * <p>A <code>null</code> reference passed to this method is a no-op.</p>
+ *
+ * <pre>
+ * StringUtils.replaceOnce(null, *, *) = null
+ * StringUtils.replaceOnce("", *, *) = ""
+ * StringUtils.replaceOnce("any", null, *) = "any"
+ * StringUtils.replaceOnce("any", *, null) = "any"
+ * StringUtils.replaceOnce("any", "", *) = "any"
+ * StringUtils.replaceOnce("aba", "a", null) = "aba"
+ * StringUtils.replaceOnce("aba", "a", "") = "ba"
+ * StringUtils.replaceOnce("aba", "a", "z") = "zba"
+ * </pre>
+ *
+ * @see #replaceTo(text:String, pattern:String, repl:String, max:int)
+ * @param text text to search and replace in, may be null
+ * @param repl the String to search for, may be null
+ * @param with the String to replace with, may be null
+ * @return the text with any replacements processed,
+ * <code>null</code> if null String input
+ */
+ public static function replaceOnce(text:String, pattern:String, repl:String):String {
+ if (text == null || isEmpty(pattern) || repl == null) {
+ return text;
+ }
+ return text.replace(new RegExp(pattern, ''), repl);
+ }
+
+ /**
+ * <p>Returns either the passed in String, or if the String is
+ * empty or <code>null</code>, the value of <code>defaultStr</code>.</p>
+ *
+ * <pre>
+ * StringUtils.defaultIfEmpty(null, "NULL") = "NULL"
+ * StringUtils.defaultIfEmpty("", "NULL") = "NULL"
+ * StringUtils.defaultIfEmpty("bat", "NULL") = "bat"
+ * </pre>
+ *
+ * @param str the String to check, may be null
+ * @param defaultStr the default String to return
+ * if the input is empty("") or <code>null</code>, may be null
+ * @return the passed in String, or the default
+ */
+ public static function defaultIfEmpty(str:String, defaultStr:String):String {
+ return isEmpty(str) ? defaultStr : str;
+ }
+
+ /**
+ * <p>Checks if a String is empty("") or null.</p>
+ *
+ * <pre>
+ * StringUtils.isEmpty(null) = true
+ * StringUtils.isEmpty("") = true
+ * StringUtils.isEmpty(" ") = false
+ * StringUtils.isEmpty("bob") = false
+ * StringUtils.isEmpty(" bob ") = false
+ * </pre>
+ *
+ * <p>NOTE: This method changed in Lang version 2.0.
+ * It no longer trims the String.
+ * That functionality is available in isBlank().</p>
+ *
+ * @param str the String to check, may be null
+ * @return <code>true</code> if the String is empty or null
+ */
+ public static function isEmpty(str:String):Boolean {
+ if (str == null) {
+ return true;
+ }
+ return str.length == 0;
+ }
+
+ /**
+ * <p>Checks if a String is not empty("") and not null.</p>
+ *
+ * <pre>
+ * StringUtils.isNotEmpty(null) = false
+ * StringUtils.isNotEmpty("") = false
+ * StringUtils.isNotEmpty(" ") = true
+ * StringUtils.isNotEmpty("bob") = true
+ * StringUtils.isNotEmpty(" bob ") = true
+ * </pre>
+ *
+ * @param str the String to check, may be null
+ * @return <code>true</code> if the String is not empty and not null
+ */
+ public static function isNotEmpty(str:String):Boolean {
+ return !isEmpty(str);
+ }
+
+ /**
+ * <p>Checks if a String is whitespace, empty("") or null.</p>
+ *
+ * <pre>
+ * StringUtils.isBlank(null) = true
+ * StringUtils.isBlank("") = true
+ * StringUtils.isBlank(" ") = true
+ * StringUtils.isBlank("bob") = false
+ * StringUtils.isBlank(" bob ") = false
+ * </pre>
+ *
+ * @param str the String to check, may be null
+ * @return <code>true</code> if the String is null, empty or whitespace
+ */
+ public static function isBlank(str:String):Boolean {
+ return isEmpty(trimToEmpty(str));
+ }
+
+ /**
+ * <p>Checks if a String is not empty(""), not <code>null</code>
+ * and not whitespace only.</p>
+ *
+ * <pre>
+ * StringUtils.isNotBlank(null) = false
+ * StringUtils.isNotBlank("") = false
+ * StringUtils.isNotBlank(" ") = false
+ * StringUtils.isNotBlank("bob") = true
+ * StringUtils.isNotBlank(" bob ") = true
+ * </pre>
+ *
+ * @param str the String to check, may be null
+ * @return <code>true</code> if the String is
+ * not empty and not null and not whitespace
+ */
+ public static function isNotBlank(str:String):Boolean {
+ return !isBlank(str);
+ }
+
+ /**
+ * <p>Removes control characters (char <= 32) from both
+ * ends of this String returning <code>null</code> if the String is
+ * empty ("") after the trim or if it is <code>null</code>.
+ *
+ * <p>The String is trimmed using #trim().
+ * Trim removes start and end characters <= 32.</p>
+ *
+ * <pre>
+ * StringUtils.trimToNull(null) = null
+ * StringUtils.trimToNull("") = null
+ * StringUtils.trimToNull(" ") = null
+ * StringUtils.trimToNull("abc") = "abc"
+ * StringUtils.trimToNull(" abc ") = "abc"
+ * </pre>
+ *
+ * @param str the String to be trimmed, may be null
+ * @return the trimmed String,
+ * <code>null</code> if only chars <= 32, empty or null String input
+ */
+ public static function trimToNull(str:String):String {
+ var trimedString:String = trim(str);
+ return isEmpty(trimedString) ? null : trimedString;
+ }
+
+ /**
+ * <p>Removes control characters (char <= 32) from both
+ * ends of this String returning an empty String ("") if the String
+ * is empty ("") after the trim or if it is <code>null</code>.
+ *
+ * <p>The String is trimmed using #trim().
+ * Trim removes start and end characters <= 32.
+ * To strip whitespace use #stripToEmpty(String).</p>
+ *
+ * <pre>
+ * StringUtils.trimToEmpty(null) = ""
+ * StringUtils.trimToEmpty("") = ""
+ * StringUtils.trimToEmpty(" ") = ""
+ * StringUtils.trimToEmpty("abc") = "abc"
+ * StringUtils.trimToEmpty(" abc ") = "abc"
+ * </pre>
+ *
+ * @param str the String to be trimmed, may be null
+ * @return the trimmed String, or an empty String if <code>null</code> input
+ */
+ public static function trimToEmpty(str:String):String {
+ return str == null ? EMPTY : trim(str);
+ }
+
+ /**
+ * <p>Capitalizes a String changing the first letter to title case.
+ * No other letters are changed.</p>
+ *
+ * A <code>null</code> input String returns <code>null</code>.</p>
+ *
+ * <pre>
+ * StringUtils.capitalize(null) = null
+ * StringUtils.capitalize("") = ""
+ * StringUtils.capitalize("cat") = "Cat"
+ * StringUtils.capitalize("cAt") = "CAt"
+ * </pre>
+ *
+ * @param str the String to capitalize, may be null
+ * @return the capitalized String, <code>null</code> if null String input
+ * @see titleize(String)
+ * @see #uncapitalize(String)
+ */
+ public static function capitalize(str:String):String {
+ if (isEmpty(str)) {
+ return str;
+ }
+ return str.charAt(0).toUpperCase() + str.substring(1);
+ }
+
+ /**
+ * <p>Uncapitalizes a String changing the first letter to title case.
+ * No other letters are changed.</p>
+ *
+ * <pre>
+ * StringUtils.uncapitalize(null) = null
+ * StringUtils.uncapitalize("") = ""
+ * StringUtils.uncapitalize("Cat") = "cat"
+ * StringUtils.uncapitalize("CAT") = "cAT"
+ * </pre>
+ *
+ * @param str the String to uncapitalize, may be null
+ * @return the uncapitalized String, <code>null</code> if null String input
+ * @see #capitalize(String)
+ */
+ public static function uncapitalize(str:String):String {
+ if (isEmpty(str)) {
+ return str;
+ }
+ return str.charAt(0).toLowerCase() + str.substring(1);
+ }
+
+ /**
+ * <p>Capitalizes all the words and replaces some characters in
+ * the string to create a nicer looking title.
+ * Titleize is meant for creating pretty output.</p>
+ *
+ * <pre>
+ * StringUtils.titleize(null) = null
+ * StringUtils.titleize("") = ""
+ * StringUtils.titleize("man from the boondocks") = "Man From The Boondocks"
+ * StringUtils.titleize("man from THE bOOndocks") = "Man From The Boondocks"
+ * </pre>
+ *
+ * @param str the String to uncapitalize, may be null
+ * @return the uncapitalized String, <code>null</code> if null String input
+ * @see #capitalize(String)
+ */
+ public static function titleize(str:String):String {
+ if (isEmpty(str)) {
+ return str;
+ }
+ var words:Array = str.toLowerCase().split(' ');
+
+ for (var i:int = 0; i < words.length; i++) {
+ words[i] = capitalize(words[i]);
+ }
+ return words.join(' ');
+ }
+
+ /**
+ * <p>Gets the substring after the first occurrence of a separator.
+ * The separator is not returned.</p>
+ *
+ * <p>A <code>null</code> string input will return <code>null</code>.
+ * An empty("") string input will return the empty string.
+ * A <code>null</code> separator will return the empty string if the
+ * input string is not <code>null</code>.</p>
+ *
+ * <pre>
+ * StringUtils.substringAfter(null, *) = null
+ * StringUtils.substringAfter("", *) = ""
+ * StringUtils.substringAfter(*, null) = ""
+ * StringUtils.substringAfter("abc", "a") = "bc"
+ * StringUtils.substringAfter("abcba", "b") = "cba"
+ * StringUtils.substringAfter("abc", "c") = ""
+ * StringUtils.substringAfter("abc", "d") = ""
+ * StringUtils.substringAfter("abc", "") = "abc"
+ * </pre>
+ *
+ * @param str the String to get a substring from, may be null
+ * @param separator the String to search for, may be null
+ * @return the substring after the first occurrence of the separator,
+ * <code>null</code> if null String input
+ */
+ public static function substringAfter(str:String, separator:String):String {
+ if (isEmpty(str)) {
+ return str;
+ }
+
+ if (separator == null) {
+ return EMPTY;
+ }
+ var pos:int = str.indexOf(separator);
+
+ if (pos == INDEX_NOT_FOUND) {
+ return EMPTY;
+ }
+ return str.substring(pos + separator.length);
+ }
+
+ /**
+ * <p>Gets the substring after the last occurrence of a separator.
+ * The separator is not returned.</p>
+ *
+ * <p>A <code>null</code> string input will return <code>null</code>.
+ * An empty("") string input will return the empty string.
+ * An empty or <code>null</code> separator will return the empty string if
+ * the input string is not <code>null</code>.</p>
+ *
+ * <pre>
+ * StringUtils.substringAfterLast(null, *) = null
+ * StringUtils.substringAfterLast("", *) = ""
+ * StringUtils.substringAfterLast(*, "") = ""
+ * StringUtils.substringAfterLast(*, null) = ""
+ * StringUtils.substringAfterLast("abc", "a") = "bc"
+ * StringUtils.substringAfterLast("abcba", "b") = "a"
+ * StringUtils.substringAfterLast("abc", "c") = ""
+ * StringUtils.substringAfterLast("a", "a") = ""
+ * StringUtils.substringAfterLast("a", "z") = ""
+ * </pre>
+ *
+ * @param str the String to get a substring from, may be null
+ * @param separator the String to search for, may be null
+ * @return the substring after the last occurrence of the separator,
+ * <code>null</code> if null String input
+ */
+ public static function substringAfterLast(str:String, separator:String):String {
+ if (isEmpty(str)) {
+ return str;
+ }
+
+ if (isEmpty(separator)) {
+ return EMPTY;
+ }
+ var pos:int = str.lastIndexOf(separator);
+
+ if (pos == INDEX_NOT_FOUND || pos == (str.length - separator.length)) {
+ return EMPTY;
+ }
+ return str.substring(pos + separator.length);
+ }
+
+ /**
+ * <p>Gets the substring before the first occurrence of a separator.
+ * The separator is not returned.</p>
+ *
+ * <p>A <code>null</code> string input will return <code>null</code>.
+ * An empty("") string input will return the empty string.
+ * A <code>null</code> separator will return the input string.</p>
+ *
+ * <pre>
+ * StringUtils.substringBefore(null, *) = null
+ * StringUtils.substringBefore("", *) = ""
+ * StringUtils.substringBefore("abc", "a") = ""
+ * StringUtils.substringBefore("abcba", "b") = "a"
+ * StringUtils.substringBefore("abc", "c") = "ab"
+ * StringUtils.substringBefore("abc", "d") = "abc"
+ * StringUtils.substringBefore("abc", "") = ""
+ * StringUtils.substringBefore("abc", null) = "abc"
+ * </pre>
+ *
+ * @param str the String to get a substring from, may be null
+ * @param separator the String to search for, may be null
+ * @return the substring before the first occurrence of the separator,
+ * <code>null</code> if null String input
+ */
+ public static function substringBefore(str:String, separator:String):String {
+ if (isEmpty(str) || separator == null) {
+ return str;
+ }
+
+ if (separator.length == 0) {
+ return EMPTY;
+ }
+ var pos:int = str.indexOf(separator);
+
+ if (pos == INDEX_NOT_FOUND) {
+ return str;
+ }
+ return str.substring(0, pos);
+ }
+
+ /**
+ * <p>Gets the substring before the last occurrence of a separator.
+ * The separator is not returned.</p>
+ *
+ * <p>A <code>null</code> string input will return <code>null</code>.
+ * An empty("") string input will return the empty string.
+ * An empty or <code>null</code> separator will return the input string.</p>
+ *
+ * <pre>
+ * StringUtils.substringBeforeLast(null, *) = null
+ * StringUtils.substringBeforeLast("", *) = ""
+ * StringUtils.substringBeforeLast("abcba", "b") = "abc"
+ * StringUtils.substringBeforeLast("abc", "c") = "ab"
+ * StringUtils.substringBeforeLast("a", "a") = ""
+ * StringUtils.substringBeforeLast("a", "z") = "a"
+ * StringUtils.substringBeforeLast("a", null) = "a"
+ * StringUtils.substringBeforeLast("a", "") = "a"
+ * </pre>
+ *
+ * @param str the String to get a substring from, may be null
+ * @param separator the String to search for, may be null
+ * @return the substring before the last occurrence of the separator,
+ * <code>null</code> if null String input
+ */
+ public static function substringBeforeLast(str:String, separator:String):String {
+ if (isEmpty(str) || isEmpty(separator)) {
+ return str;
+ }
+ var pos:int = str.lastIndexOf(separator);
+
+ if (pos == INDEX_NOT_FOUND) {
+ return str;
+ }
+ return str.substring(0, pos);
+ }
+
+ /**
+ * <p>Gets the String that is nested in between two Strings.
+ * Only the first match is returned.</p>
+ *
+ * <p>A <code>null</code> input String returns <code>null</code>.
+ * A <code>null</code> open/close returns <code>null</code>(no match).
+ * An empty("") open/close returns an empty string.</p>
+ *
+ * <pre>
+ * StringUtils.substringBetween(null, *, *) = null
+ * StringUtils.substringBetween("", "", "") = ""
+ * StringUtils.substringBetween("", "", "tag") = null
+ * StringUtils.substringBetween("", "tag", "tag") = null
+ * StringUtils.substringBetween("yabcz", null, null) = null
+ * StringUtils.substringBetween("yabcz", "", "") = ""
+ * StringUtils.substringBetween("yabcz", "y", "z") = "abc"
+ * StringUtils.substringBetween("yabczyabcz", "y", "z") = "abc"
+ * </pre>
+ *
+ * @param str the String containing the substring, may be null
+ * @param open the String before the substring, may be null
+ * @param close the String after the substring, may be null
+ * @return the substring, <code>null</code> if no match
+ */
+ public static function substringBetween(str:String, open:String, close:String):String {
+ if (str == null || open == null || close == null) {
+ return null;
+ }
+ var start:int = str.indexOf(open);
+
+ if (start != INDEX_NOT_FOUND) {
+ var end:int = str.indexOf(close, start + open.length);
+
+ if (end != INDEX_NOT_FOUND) {
+ return str.substring(start + open.length, end);
+ }
+ }
+ return null;
+ }
+
+ /**
+ * <p>Strips any of a set of characters from the start and end of a String.
+ * This is similar to #trim() but allows the characters
+ * to be stripped to be controlled.</p>
+ *
+ * <p>A <code>null</code> input String returns <code>null</code>.
+ * An empty string("") input returns the empty string.</p>
+ *
+ * <pre>
+ * StringUtils.strip(null, *) = null
+ * StringUtils.strip("", *) = ""
+ * StringUtils.strip("abc", null) = "abc"
+ * StringUtils.strip(" abc", null) = "abc"
+ * StringUtils.strip("abc ", null) = "abc"
+ * StringUtils.strip(" abc ", null) = "abc"
+ * StringUtils.strip(" abcyx", "xyz") = " abc"
+ * </pre>
+ *
+ * @param str the String to remove characters from, may be null
+ * @param stripChars the characters to remove, null treated as whitespace
+ * @return the stripped String, <code>null</code> if null String input
+ */
+ public static function strip(str:String, stripChars:String):String {
+ if (isEmpty(str)) {
+ return str;
+ }
+ return stripEnd(stripStart(str, stripChars), stripChars);
+ }
+
+ /**
+ * <p>Strips any of a set of characters from the start of a String.</p>
+ *
+ * <p>A <code>null</code> input String returns <code>null</code>.
+ * An empty string("") input returns the empty string.</p>
+ *
+ * <pre>
+ * StringUtils.stripStart(null, *) = null
+ * StringUtils.stripStart("", *) = ""
+ * StringUtils.stripStart("abc", "") = "abc"
+ * StringUtils.stripStart("abc", null) = "abc"
+ * StringUtils.stripStart(" abc", null) = "abc"
+ * StringUtils.stripStart("abc ", null) = "abc "
+ * StringUtils.stripStart(" abc ", null) = "abc "
+ * StringUtils.stripStart("yxabc ", "xyz") = "abc "
+ * </pre>
+ *
+ * @param str the String to remove characters from, may be null
+ * @param stripChars the characters to remove, null treated as whitespace
+ * @return the stripped String, <code>null</code> if null String input
+ */
+ public static function stripStart(str:String, stripChars:String):String {
+ if (isEmpty(str)) {
+ return str;
+ }
+ var p:RegExp = new RegExp('^[' + (stripChars != null ? stripChars : ' ') + ']*', '');
+ return str.replace(p, '');
+ }
+
+ /**
+ * <p>Strips any of a set of characters from the end of a String.</p>
+ *
+ * <p>A <code>null</code> input String returns <code>null</code>.
+ * An empty string("") input returns the empty string.</p>
+ *
+ * <p>If the stripChars String is <code>null</code>, whitespace is
+ * stripped.</p>
+ *
+ * <pre>
+ * StringUtils.stripEnd(null, *) = null
+ * StringUtils.stripEnd("", *) = ""
+ * StringUtils.stripEnd("abc", "") = "abc"
+ * StringUtils.stripEnd("abc", null) = "abc"
+ * StringUtils.stripEnd(" abc", null) = " abc"
+ * StringUtils.stripEnd("abc ", null) = "abc"
+ * StringUtils.stripEnd(" abc ", null) = " abc"
+ * StringUtils.stripEnd(" abcyx", "xyz") = " abc"
+ * </pre>
+ *
+ * @param str the String to remove characters from, may be null
+ * @param stripChars the characters to remove, null treated as whitespace
+ * @return the stripped String, <code>null</code> if null String input
+ */
+ public static function stripEnd(str:String, stripChars:String):String {
+ if (isEmpty(str)) {
+ return str;
+ }
+ var p:RegExp = new RegExp('[' + (stripChars != null ? stripChars : ' ') + ']*$', '');
+ return str.replace(p, '');
+ }
+
+ /**
+ * <p>Abbreviates a String using ellipses. This will turn
+ * "Now is the time for all good men" into "...is the time for..."</p>
+ *
+ * <p>Works like <code>abbreviate(String, int)</code>, but allows you to specify
+ * a "left edge" offset. Note that this left edge is not necessarily going to
+ * be the leftmost character in the result, or the first character following the
+ * ellipses, but it will appear somewhere in the result.
+ *
+ * <p>In no case will it return a String of length greater than
+ * <code>maxWidth</code>.</p>
+ *
+ * <pre>
+ * StringUtils.abbreviate(null, *, *) = null
+ * StringUtils.abbreviate("", 0, 4) = ""
+ * StringUtils.abbreviate("abcdefghijklmno", -1, 10) = "abcdefg..."
+ * StringUtils.abbreviate("abcdefghijklmno", 0, 10) = "abcdefg..."
+ * StringUtils.abbreviate("abcdefghijklmno", 1, 10) = "abcdefg..."
+ * StringUtils.abbreviate("abcdefghijklmno", 4, 10) = "abcdefg..."
+ * StringUtils.abbreviate("abcdefghijklmno", 5, 10) = "...fghi..."
+ * StringUtils.abbreviate("abcdefghijklmno", 6, 10) = "...ghij..."
+ * StringUtils.abbreviate("abcdefghijklmno", 8, 10) = "...ijklmno"
+ * StringUtils.abbreviate("abcdefghijklmno", 10, 10) = "...ijklmno"
+ * StringUtils.abbreviate("abcdefghijklmno", 12, 10) = "...ijklmno"
+ * StringUtils.abbreviate("abcdefghij", 0, 3) = IllegalArgumentException
+ * StringUtils.abbreviate("abcdefghij", 5, 6) = IllegalArgumentException
+ * </pre>
+ *
+ * @param str the String to check, may be null
+ * @param offset left edge of source String
+ * @param maxWidth maximum length of result String, must be at least 4
+ * @return abbreviated String, <code>null</code> if null String input
+ * @throws IllegalArgumentException if the width is too small
+ */
+ public static function abbreviate(str:String, offset:int, maxWidth:int):String {
+ if (str == null) {
+ return str;
+ }
+
+ if (maxWidth < 4) {
+ throw new IllegalArgumentError("Minimum abbreviation width is 4");
+ }
+
+ if (str.length <= maxWidth) {
+ return str;
+ }
+
+ if (offset > str.length) {
+ offset = str.length;
+ }
+
+ if ((str.length - offset) < (maxWidth - 3)) {
+ offset = str.length - (maxWidth - 3);
+ }
+
+ if (offset <= 4) {
+ return str.substring(0, maxWidth - 3) + "...";
+ }
+
+ if (maxWidth < 7) {
+ throw new IllegalArgumentError("Minimum abbreviation width with offset is 7");
+ }
+
+ if ((offset + (maxWidth - 3)) < str.length) {
+ return "..." + abbreviate(str.substring(offset), 0, maxWidth - 3);
+ }
+ return "..." + str.substring(str.length - (maxWidth - 3));
+ }
+
+ /**
+ * <p>Finds the n-th index within a String, handling <code>null</code>.
+ * This method uses String#indexOf(String).</p>
+ *
+ * <p>A <code>null</code> String will return <code>-1</code>.</p>
+ *
+ * <pre>
+ * StringUtils.ordinalIndexOf(null, *, *) = -1
+ * StringUtils.ordinalIndexOf(*, null, *) = -1
+ * StringUtils.ordinalIndexOf("", "", *) = 0
+ * StringUtils.ordinalIndexOf("aabaabaa", "a", 1) = 0
+ * StringUtils.ordinalIndexOf("aabaabaa", "a", 2) = 1
+ * StringUtils.ordinalIndexOf("aabaabaa", "b", 1) = 2
+ * StringUtils.ordinalIndexOf("aabaabaa", "b", 2) = 5
+ * StringUtils.ordinalIndexOf("aabaabaa", "ab", 1) = 1
+ * StringUtils.ordinalIndexOf("aabaabaa", "ab", 2) = 4
+ * StringUtils.ordinalIndexOf("aabaabaa", "", 1) = 0
+ * StringUtils.ordinalIndexOf("aabaabaa", "", 2) = 0
+ * </pre>
+ *
+ * @param str the String to check, may be null
+ * @param searchStr the String to find, may be null
+ * @param ordinal the n-th <code>searchStr</code> to find
+ * @return the n-th index of the search String,
+ * <code>-1</code>(<code>INDEX_NOT_FOUND</code>) if no match or <code>null</code> string input
+ */
+ public static function ordinalIndexOf(str:String, searchStr:String, ordinal:int):int {
+ if (str == null || searchStr == null || ordinal <= 0) {
+ return INDEX_NOT_FOUND;
+ }
+
+ if (searchStr.length == 0) {
+ return 0;
+ }
+ var found:int = 0;
+ var index:int = INDEX_NOT_FOUND;
+
+ do {
+ index = str.indexOf(searchStr, index + 1);
+
+ if (index < 0) {
+ return index;
+ }
+ found++;
+ } while (found < ordinal);
+ return index;
+ }
+
+ /**
+ * <p>Counts how many times the substring appears in the larger String.</p>
+ *
+ * <p>A <code>null</code> or empty("") String input returns <code>0</code>.</p>
+ *
+ * <pre>
+ * StringUtils.countMatches(null, *) = 0
+ * StringUtils.countMatches("", *) = 0
+ * StringUtils.countMatches("abba", null) = 0
+ * StringUtils.countMatches("abba", "") = 0
+ * StringUtils.countMatches("abba", "a") = 2
+ * StringUtils.countMatches("abba", "ab") = 1
+ * StringUtils.countMatches("abba", "xxx") = 0
+ * </pre>
+ *
+ * @param str the String to check, may be null
+ * @param sub the substring to count, may be null
+ * @return the number of occurrences, 0 if either String is <code>null</code>
+ */
+ public static function countMatches(str:String, sub:String):int {
+ if (isEmpty(str) || isEmpty(sub)) {
+ return 0;
+ }
+ return str.match(new RegExp('(' + sub + ')', 'g')).length;
+ }
+
+ /**
+ * <p>Checks if String contains a search String, handling <code>null</code>.
+ *
+ * <p>A <code>null</code> String will return <code>false</code>.</p>
+ *
+ * <pre>
+ * StringUtils.contains(null, *) = false
+ * StringUtils.contains(*, null) = false
+ * StringUtils.contains("", "") = true
+ * StringUtils.contains("abc", "") = true
+ * StringUtils.contains("abc", "a") = true
+ * StringUtils.contains("abc", "z") = false
+ * </pre>
+ *
+ * @param str the String to check, may be null
+ * @param searchStr the String to find, may be null
+ * @return true if the String contains the search String,
+ * false if not or <code>null</code> string input
+ */
+ public static function contains(str:String, searchStr:String):Boolean {
+ if (str == null || searchStr == null) {
+ return false;
+ }
+ return new RegExp('(' + searchStr + ')', 'g').test(str);
+ }
+
+ /**
+ * <p>Checks that the String does not contain certain characters.</p>
+ *
+ * <p>A <code>null</code> String will return <code>true</code>.
+ * A <code>null</code> invalid character array will return <code>true</code>.
+ * An empty String("") always returns true.</p>
+ *
+ * <pre>
+ * StringUtils.containsNone(null, *) = true
+ * StringUtils.containsNone(*, null) = true
+ * StringUtils.containsNone("", *) = true
+ * StringUtils.containsNone("ab", "") = true
+ * StringUtils.containsNone("abab", "xyz") = true
+ * StringUtils.containsNone("ab1", "xyz") = true
+ * StringUtils.containsNone("abz", "xyz") = false
+ * </pre>
+ *
+ * @param str the String to check, may be null
+ * @param invalidChars a String of invalid chars, may be null
+ * @return true if it contains none of the invalid chars, or is null
+ */
+ public static function containsNone(str:String, invalidChars:String):Boolean {
+ if (isEmpty(str) || invalidChars == null) {
+ return true;
+ }
+ return new RegExp('^[^' + invalidChars + ']*$', '').test(str);
+ }
+
+ /**
+ * <p>Checks if the String contains only certain characters.</p>
+ *
+ * <p>A <code>null</code> String will return <code>false</code>.
+ * A <code>null</code> valid character String will return <code>false</code>.
+ * An empty String("") always returns <code>true</code>.</p>
+ *
+ * <pre>
+ * StringUtils.containsOnly(null, *) = false
+ * StringUtils.containsOnly(*, null) = false
+ * StringUtils.containsOnly("", *) = true
+ * StringUtils.containsOnly("ab", "") = false
+ * StringUtils.containsOnly("abab", "abc") = true
+ * StringUtils.containsOnly("ab1", "abc") = false
+ * StringUtils.containsOnly("abz", "abc") = false
+ * </pre>
+ *
+ * @param str the String to check, may be null
+ * @param validChars a String of valid chars, may be null
+ * @return true if it only contains valid chars and is non-null
+ */
+ public static function containsOnly(str:String, validChars:String):Boolean {
+ if (str == null || isEmpty(validChars)) {
+ return false;
+ }
+
+ if (str.length == 0) {
+ return true;
+ }
+ return new RegExp('^[' + validChars + ']*$', 'g').test(str);
+ }
+
+ /**
+ * <p>Search a String to find the first index of any
+ * character in the given set of characters.</p>
+ *
+ * <p>A <code>null</code> String will return <code>-1</code>.
+ * A <code>null</code> search string will return <code>-1</code>.</p>
+ *
+ * <pre>
+ * StringUtils.indexOfAny(null, *) = -1
+ * StringUtils.indexOfAny("", *) = -1
+ * StringUtils.indexOfAny(*, null) = -1
+ * StringUtils.indexOfAny(*, "") = -1
+ * StringUtils.indexOfAny("zzabyycdxx", "za") = 0
+ * StringUtils.indexOfAny("zzabyycdxx", "by") = 3
+ * StringUtils.indexOfAny("aba","z") = -1
+ * </pre>
+ *
+ * @param str the String to check, may be null
+ * @param searchChars the chars to search for, may be null
+ * @return the index of any of the chars, -1 if no match or null input
+ */
+ public static function indexOfAny(str:String, searchChars:String):int {
+ if (isEmpty(str) || isEmpty(searchChars)) {
+ return INDEX_NOT_FOUND;
+ }
+ return str.search(new RegExp('[' + searchChars + ']', ''));
+ }
+
+ /**
+ * <p>Search a String to find the first index of any
+ * character not in the given set of characters.</p>
+ *
+ * <p>A <code>null</code> String will return <code>-1</code>.
+ * A <code>null</code> search string will return <code>-1</code>.</p>
+ *
+ * <pre>
+ * StringUtils.indexOfAnyBut(null, *) = -1
+ * StringUtils.indexOfAnyBut("", *) = -1
+ * StringUtils.indexOfAnyBut(*, null) = -1
+ * StringUtils.indexOfAnyBut(*, "") = -1
+ * StringUtils.indexOfAnyBut("zzabyycdxx", "za") = 3
+ * StringUtils.indexOfAnyBut("aba","ab") = -1
+ * </pre>
+ *
+ * @param str the String to check, may be null
+ * @param searchChars the chars to search for, may be null
+ * @return the index of any of the chars, -1 if no match or null input
+ */
+ public static function indexOfAnyBut(str:String, searchChars:String):int {
+ if (isEmpty(str) || isEmpty(searchChars)) {
+ return INDEX_NOT_FOUND;
+ }
+ return str.search(new RegExp('[^' + searchChars + ']', ''));
+ }
+
+ /**
+ * <p>Compares two Strings, and returns the portion where they differ.
+ *(More precisely, return the remainder of the second String,
+ * starting from where it's different from the first.)</p>
+ *
+ * <p>For example,
+ * <code>difference("i am a machine", "i am a robot") -> "robot"</code>.</p>
+ *
+ * <pre>
+ * StringUtils.difference(null, null) = null
+ * StringUtils.difference("", "") = ""
+ * StringUtils.difference("", "abc") = "abc"
+ * StringUtils.difference("abc", "") = ""
+ * StringUtils.difference("abc", "abc") = ""
+ * StringUtils.difference("ab", "abxyz") = "xyz"
+ * StringUtils.difference("abcde", "abxyz") = "xyz"
+ * StringUtils.difference("abcde", "xyz") = "xyz"
+ * </pre>
+ *
+ * @param str1 the first String, may be null
+ * @param str2 the second String, may be null
+ * @return the portion of str2 where it differs from str1; returns the
+ * empty String if they are equal
+ */
+ public static function difference(str1:String, str2:String):String {
+ if (str1 == null) {
+ return str2;
+ }
+
+ if (str2 == null) {
+ return str1;
+ }
+ var att:int = indexOfDifference(str1, str2);
+
+ if (att == -1) {
+ return EMPTY;
+ }
+ return str2.substring(att);
+ }
+
+ /**
+ * <p>Compares two Strings, and returns the index at which the
+ * Strings begin to differ.</p>
+ *
+ * <p>For example,
+ * <code>indexOfDifference("i am a machine", "i am a robot") -> 7</code></p>
+ *
+ * <pre>
+ * StringUtils.indexOfDifference(null, null) = -1
+ * StringUtils.indexOfDifference("", "") = -1
+ * StringUtils.indexOfDifference("", "abc") = 0
+ * StringUtils.indexOfDifference("abc", "") = 0
+ * StringUtils.indexOfDifference("abc", "abc") = -1
+ * StringUtils.indexOfDifference("ab", "abxyz") = 2
+ * StringUtils.indexOfDifference("abcde", "abxyz") = 2
+ * StringUtils.indexOfDifference("abcde", "xyz") = 0
+ * </pre>
+ *
+ * @param str1 the first String, may be null
+ * @param str2 the second String, may be null
+ * @return the index where str2 and str1 begin to differ; -1 if they are equal
+ */
+ public static function indexOfDifference(str1:String, str2:String):int {
+ if (str1 == str2) {
+ return INDEX_NOT_FOUND;
+ }
+
+ if (isEmpty(str1) || isEmpty(str2)) {
+ return 0;
+ }
+ var charIndex:int;
+
+ for (charIndex = 0; charIndex < str1.length && charIndex < str2.length; ++charIndex) {
+ if (str1.charAt(charIndex) != str2.charAt(charIndex)) {
+ break;
+ }
+ }
+
+ if (charIndex < str2.length || charIndex < str1.length) {
+ return charIndex;
+ }
+ return INDEX_NOT_FOUND;
+ }
+
+ /**
+ * <p>Compares two Strings, returning <code>true</code> if they are equal.</p>
+ *
+ * <p><code>null</code>s are handled without exceptions. Two <code>null</code>
+ * references are considered to be equal. The comparison is case sensitive.</p>
+ *
+ * <pre>
+ * StringUtils.equals(null, null) = true
+ * StringUtils.equals(null, "abc") = false
+ * StringUtils.equals("abc", null) = false
+ * StringUtils.equals("abc", "abc") = true
+ * StringUtils.equals("abc", "ABC") = false
+ * </pre>
+ *
+ * @param str1 the first String, may be null
+ * @param str2 the second String, may be null
+ * @return <code>true</code> if the Strings are equal, case sensitive, or
+ * both <code>null</code>
+ */
+ public static function equals(str1:String, str2:String):Boolean {
+ return str1 === str2;
+ }
+
+ /**
+ * <p>Compares two Strings, returning <code>true</code> if they are equal ignoring
+ * the case.</p>
+ *
+ * <p><code>null</code>s are handled without exceptions. Two <code>null</code>
+ * references are considered equal. Comparison is case insensitive.</p>
+ *
+ * <pre>
+ * StringUtils.equalsIgnoreCase(null, null) = true
+ * StringUtils.equalsIgnoreCase(null, "abc") = false
+ * StringUtils.equalsIgnoreCase("abc", null) = false
+ * StringUtils.equalsIgnoreCase("abc", "abc") = true
+ * StringUtils.equalsIgnoreCase("abc", "ABC") = true
+ * </pre>
+ *
+ * @param str1 the first String, may be null
+ * @param str2 the second String, may be null
+ * @return <code>true</code> if the Strings are equal, case insensitive, or
+ * both <code>null</code>
+ */
+ public static function equalsIgnoreCase(str1:String, str2:String):Boolean {
+ if (str1 == null && str2 == null) {
+ return true;
+ } else if (str1 == null || str2 == null) {
+ return false;
+ }
+ return equals(str1.toLowerCase(), str2.toLowerCase());
+ }
+
+ /**
+ * <p>Checks if the String contains only unicode letters.</p>
+ *
+ * <p><code>null</code> will return <code>false</code>.
+ * An empty String("") will return <code>true</code>.</p>
+ *
+ * <pre>
+ * StringUtils.isAlpha(null) = false
+ * StringUtils.isAlpha("") = true
+ * StringUtils.isAlpha(" ") = false
+ * StringUtils.isAlpha("abc") = true
+ * StringUtils.isAlpha("ab2c") = false
+ * StringUtils.isAlpha("ab-c") = false
+ * </pre>
+ *
+ * @param str the String to check, may be null
+ * @return <code>true</code> if only contains letters, and is non-null
+ */
+ public static function isAlpha(str:String):Boolean {
+ return testString(str, /^[a-zA-Z]*$/);
+ }
+
+ /**
+ * <p>Checks if the String contains only unicode letters and
+ * space(' ').</p>
+ *
+ * <p><code>null</code> will return <code>false</code>
+ * An empty String("") will return <code>true</code>.</p>
+ *
+ * <pre>
+ * StringUtils.isAlphaSpace(null) = false
+ * StringUtils.isAlphaSpace("") = true
+ * StringUtils.isAlphaSpace(" ") = true
+ * StringUtils.isAlphaSpace("abc") = true
+ * StringUtils.isAlphaSpace("ab c") = true
+ * StringUtils.isAlphaSpace("ab2c") = false
+ * StringUtils.isAlphaSpace("ab-c") = false
+ * </pre>
+ *
+ * @param str the String to check, may be null
+ * @return <code>true</code> if only contains letters and space,
+ * and is non-null
+ */
+ public static function isAlphaSpace(str:String):Boolean {
+ return testString(str, /^[a-zA-Z\s]*$/);
+ }
+
+ /**
+ * <p>Checks if the String contains only unicode letters or digits.</p>
+ *
+ * <p><code>null</code> will return <code>false</code>.
+ * An empty String("") will return <code>true</code>.</p>
+ *
+ * <pre>
+ * StringUtils.isAlphanumeric(null) = false
+ * StringUtils.isAlphanumeric("") = true
+ * StringUtils.isAlphanumeric(" ") = false
+ * StringUtils.isAlphanumeric("abc") = true
+ * StringUtils.isAlphanumeric("ab c") = false
+ * StringUtils.isAlphanumeric("ab2c") = true
+ * StringUtils.isAlphanumeric("ab-c") = false
+ * </pre>
+ *
+ * @param str the String to check, may be null
+ * @return <code>true</code> if only contains letters or digits,
+ * and is non-null
+ */
+ public static function isAlphanumeric(str:String):Boolean {
+ return testString(str, /^[a-zA-Z0-9]*$/);
+ }
+
+ /**
+ * <p>Checks if the String contains only unicode letters, digits
+ * or space(<code>' '</code>).</p>
+ *
+ * <p><code>null</code> will return <code>false</code>.
+ * An empty String("") will return <code>true</code>.</p>
+ *
+ * <pre>
+ * StringUtils.isAlphanumericSpace(null) = false
+ * StringUtils.isAlphanumericSpace("") = true
+ * StringUtils.isAlphanumericSpace(" ") = true
+ * StringUtils.isAlphanumericSpace("abc") = true
+ * StringUtils.isAlphanumericSpace("ab c") = true
+ * StringUtils.isAlphanumericSpace("ab2c") = true
+ * StringUtils.isAlphanumericSpace("ab-c") = false
+ * </pre>
+ *
+ * @param str the String to check, may be null
+ * @return <code>true</code> if only contains letters, digits or space,
+ * and is non-null
+ */
+ public static function isAlphanumericSpace(str:String):Boolean {
+ return testString(str, /^[a-zA-Z0-9\s]*$/);
+ }
+
+ /**
+ * <p>Checks if the String contains only unicode digits.
+ * A decimal point is not a unicode digit and returns false.</p>
+ *
+ * <p><code>null</code> will return <code>false</code>.
+ * An empty String("") will return <code>true</code>.</p>
+ *
+ * <pre>
+ * StringUtils.isNumeric(null) = false
+ * StringUtils.isNumeric("") = true
+ * StringUtils.isNumeric(" ") = false
+ * StringUtils.isNumeric("123") = true
+ * StringUtils.isNumeric("12 3") = false
+ * StringUtils.isNumeric("ab2c") = false
+ * StringUtils.isNumeric("12-3") = false
+ * StringUtils.isNumeric("12.3") = false
+ * </pre>
+ *
+ * @param str the String to check, may be null
+ * @return <code>true</code> if only contains digits, and is non-null
+ */
+ public static function isNumeric(str:String):Boolean {
+ return testString(str, /^[0-9]*$/);
+ }
+
+ /**
+ * <p>Checks if the String contains only unicode digits or space
+ *(<code>' '</code>).
+ * A decimal point is not a unicode digit and returns false.</p>
+ *
+ * <p><code>null</code> will return <code>false</code>.
+ * An empty String("") will return <code>true</code>.</p>
+ *
+ * <pre>
+ * StringUtils.isNumericSpace(null) = false
+ * StringUtils.isNumericSpace("") = true
+ * StringUtils.isNumericSpace(" ") = true
+ * StringUtils.isNumericSpace("123") = true
+ * StringUtils.isNumericSpace("12 3") = true
+ * StringUtils.isNumericSpace("ab2c") = false
+ * StringUtils.isNumericSpace("12-3") = false
+ * StringUtils.isNumericSpace("12.3") = false
+ * </pre>
+ *
+ * @param str the String to check, may be null
+ * @return <code>true</code> if only contains digits or space,
+ * and is non-null
+ */
+ public static function isNumericSpace(str:String):Boolean {
+ return testString(str, /^[0-9\s]*$/);
+ }
+
+ /**
+ * <p>Checks if the String contains only whitespace.</p>
+ *
+ * <p><code>null</code> will return <code>false</code>.
+ * An empty String("") will return <code>true</code>.</p>
+ *
+ * <pre>
+ * StringUtils.isWhitespace(null) = false
+ * StringUtils.isWhitespace("") = true
+ * StringUtils.isWhitespace(" ") = true
+ * StringUtils.isWhitespace("abc") = false
+ * StringUtils.isWhitespace("ab2c") = false
+ * StringUtils.isWhitespace("ab-c") = false
+ * </pre>
+ *
+ * @param str the String to check, may be null
+ * @return <code>true</code> if only contains whitespace, and is non-null
+ */
+ public static function isWhitespace(str:String):Boolean {
+ return testString(str, /^[\s]*$/);
+ }
+
+ private static function testString(str:String, pattern:RegExp):Boolean {
+ return str != null && pattern.test(str);
+ }
+
+ /**
+ * <p>Overlays part of a String with another String.</p>
+ *
+ * <p>A <code>null</code> string input returns <code>null</code>.
+ * A negative index is treated as zero.
+ * An index greater than the string length is treated as the string length.
+ * The start index is always the smaller of the two indices.</p>
+ *
+ * <pre>
+ * StringUtils.overlay(null, *, *, *) = null
+ * StringUtils.overlay("", "abc", 0, 0) = "abc"
+ * StringUtils.overlay("abcdef", null, 2, 4) = "abef"
+ * StringUtils.overlay("abcdef", "", 2, 4) = "abef"
+ * StringUtils.overlay("abcdef", "", 4, 2) = "abef"
+ * StringUtils.overlay("abcdef", "zzzz", 2, 4) = "abzzzzef"
+ * StringUtils.overlay("abcdef", "zzzz", 4, 2) = "abzzzzef"
+ * StringUtils.overlay("abcdef", "zzzz", -1, 4) = "zzzzef"
+ * StringUtils.overlay("abcdef", "zzzz", 2, 8) = "abzzzz"
+ * StringUtils.overlay("abcdef", "zzzz", -2, -3) = "zzzzabcdef"
+ * StringUtils.overlay("abcdef", "zzzz", 8, 10) = "abcdefzzzz"
+ * </pre>
+ *
+ * @param str the String to do overlaying in, may be null
+ * @param overlay the String to overlay, may be null
+ * @param start the position to start overlaying at
+ * @param end the position to stop overlaying before
+ * @return overlayed String, <code>null</code> if null String input
+ */
+ public static function overlay(str:String, overlay:String, start:int, end:int):String {
+ if (str == null) {
+ return null;
+ }
+
+ if (overlay == null) {
+ overlay = EMPTY;
+ }
+ var len:int = str.length;
+
+ if (start < 0) {
+ start = 0;
+ }
+
+ if (start > len) {
+ start = len;
+ }
+
+ if (end < 0) {
+ end = 0;
+ }
+
+ if (end > len) {
+ end = len;
+ }
+
+ if (start > end) {
+ var temp:int = start; // NO PMD WronglyNamedVariable
+ start = end;
+ end = temp;
+ }
+ return str.substring(0, start).concat(overlay).concat(str.substring(end));
+ }
+
+ /**
+ * <p>Removes all occurances of a substring from within the source string.</p>
+ *
+ * <p>A <code>null</code> source string will return <code>null</code>.
+ * An empty("") source string will return the empty string.
+ * A <code>null</code> remove string will return the source string.
+ * An empty("") remove string will return the source string.</p>
+ *
+ * <pre>
+ * StringUtils.remove(null, *) = null
+ * StringUtils.remove("", *) = ""
+ * StringUtils.remove(*, null) = *
+ * StringUtils.remove(*, "") = *
+ * StringUtils.remove("queued", "ue") = "qd"
+ * StringUtils.remove("queued", "zz") = "queued"
+ * </pre>
+ *
+ * @param str the source String to search, may be null
+ * @param remove the String to search for and remove, may be null
+ * @return the substring with the string removed if found,
+ * <code>null</code> if null String input
+ */
+ public static function remove(str:String, remove:String):String {
+ return safeRemove(str, new RegExp(remove, 'g'));
+ }
+
+ /**
+ * <p>Removes a substring only if it is at the end of a source string,
+ * otherwise returns the source string.</p>
+ *
+ * <p>A <code>null</code> source string will return <code>null</code>.
+ * An empty("") source string will return the empty string.
+ * A <code>null</code> search string will return the source string.</p>
+ *
+ * <pre>
+ * StringUtils.removeEnd(null, *) = null
+ * StringUtils.removeEnd("", *) = ""
+ * StringUtils.removeEnd(*, null) = *
+ * StringUtils.removeEnd("www.domain.com", ".com") = "www.domain"
+ * StringUtils.removeEnd("www.domain.com", "domain") = "www.domain.com"
+ * StringUtils.removeEnd("abc", "") = "abc"
+ * </pre>
+ *
+ * @param str the source String to search, may be null
+ * @param remove the String to search for and remove, may be null
+ * @return the substring with the string removed if found,
+ * <code>null</code> if null String input
+ */
+ public static function removeEnd(str:String, remove:String):String {
+ return safeRemove(str, new RegExp(remove + '$', ''));
+ }
+
+ /**
+ * <p>Removes a substring only if it is at the begining of a source string,
+ * otherwise returns the source string.</p>
+ *
+ * <p>A <code>null</code> source string will return <code>null</code>.
+ * An empty("") source string will return the empty string.
+ * A <code>null</code> search string will return the source string.</p>
+ *
+ * <pre>
+ * StringUtils.removeStart(null, *) = null
+ * StringUtils.removeStart("", *) = ""
+ * StringUtils.removeStart(*, null) = *
+ * StringUtils.removeStart("www.domain.com", "www.") = "domain.com"
+ * StringUtils.removeStart("domain.com", "www.") = "domain.com"
+ * StringUtils.removeStart("www.domain.com", "domain") = "www.domain.com"
+ * StringUtils.removeStart("abc", "") = "abc"
+ * </pre>
+ *
+ * @param str the source String to search, may be null
+ * @param remove the String to search for and remove, may be null
+ * @return the substring with the string removed if found,
+ * <code>null</code> if null String input
+ */
+ public static function removeStart(str:String, remove:String):String {
+ return safeRemove(str, new RegExp('^' + remove, ''));
+ }
+
+ private static function safeRemove(str:String, pattern:RegExp):String {
+ if (isEmpty(str)) {
+ return str;
+ }
+ return str.replace(pattern, '');
+ }
+
+ /**
+ * <p>Checks if the String end characters match the given end string.</p>
+ *
+ * <p><code>null</code> will return <code>false</code>.
+ *
+ * <pre>
+ * StringUtils.endsWith(null, *) = false
+ * StringUtils.endsWith(null, null) = false
+ * StringUtils.endsWith(*, null) = false
+ * StringUtils.endsWith("www.domain.com", "com") = true
+ * </pre>
+ *
+ * @param str the String to check, may be null
+ * @param end the string to compare
+ * @return <code>true</code> if only contains whitespace, and is non-null
+ */
+ public static function endsWith(str:String, end:String):Boolean {
+ return testString(str, new RegExp(end + '$', ''));
+ }
+
+ /**
+ * <p>Checks if the String start characters match the given start string.</p>
+ *
+ * <p><code>null</code> will return <code>false</code>.
+ *
+ * <pre>
+ * StringUtils.startsWith(null, *) = false
+ * StringUtils.startsWith(null, null) = false
+ * StringUtils.startsWith(*, null) = false
+ * StringUtils.startsWith("www.domain.com", "www.") = true
+ * </pre>
+ *
+ * @param str the String to check, may be null
+ * @param start the string to compare
+ * @return <code>true</code> if only contains whitespace, and is non-null
+ */
+ public static function startsWith(str:String, start:String):Boolean {
+ return testString(str, new RegExp('^' + start, ''));
+ }
+
+ /**
+ * Compares two strings lexicographically, ignoring case
+ * differences. This method returns an integer whose sign is that of
+ * calling <code>compareTo</code> with normalized versions of the strings
+ * where case differences have been eliminated by calling
+ * <code>Character.toLowerCase(Character.toUpperCase(character))</code> on
+ * each character.
+ * <p>
+ *
+ * @param str1 the <code>String</code> to be compared.
+ * @param str2 the <code>String</code> to be compared.
+ * @return a negative integer, zero, or a positive integer as the
+ * specified String is greater than, equal to, or less
+ * than this String, ignoring case considerations.
+ */
+ public static function compareToIgnoreCase(str1:String, str2:String):int {
+ if (str1 == null) {
+ str1 = "";
+ }
+
+ if (str2 == null) {
+ str2 = "";
+ }
+
+ return compareTo(str1.toLowerCase(), str2.toLowerCase());
+ }
+
+ /**
+ * Compares two strings lexicographically.
+ * The comparison is based on the Unicode value of each character in
+ * the strings. The character sequence represented by this
+ * <code>String</code> object is compared lexicographically to the
+ * character sequence represented by the argument string. The result is
+ * a negative integer if this <code>String</code> object
+ * lexicographically precedes the argument string. The result is a
+ * positive integer if this <code>String</code> object lexicographically
+ * follows the argument string. The result is zero if the strings
+ * are equal; <code>compareTo</code> returns <code>0</code> exactly when
+ * the #equals(Object) method would return <code>true</code>.
+ * <p>
+ * This is the definition of lexicographic ordering. If two strings are
+ * different, then either they have different characters at some index
+ * that is a valid index for both strings, or their lengths are different,
+ * or both. If they have different characters at one or more index
+ * positions, let <i>k</i> be the smallest such index; then the string
+ * whose character at position <i>k</i> has the smaller value, as
+ * determined by using the < operator, lexicographically precedes the
+ * other string. In this case, <code>compareTo</code> returns the
+ * difference of the two character values at position <code>k</code> in
+ * the two string -- that is, the value:
+ * <blockquote><pre>
+ * this.charAt(k)-anotherString.charAt(k)
+ * </pre></blockquote>
+ * If there is no index position at which they differ, then the shorter
+ * string lexicographically precedes the longer string. In this case,
+ * <code>compareTo</code> returns the difference of the lengths of the
+ * strings -- that is, the value:
+ * <blockquote><pre>
+ * this.length-anotherString.length
+ * </pre></blockquote>
+ *
+ * @param anotherString the <code>String</code> to be compared.
+ * @return the value <code>0</code> if the argument string is equal to
+ * this string; a value less than <code>0</code> if this string
+ * is lexicographically less than the string argument; and a
+ * value greater than <code>0</code> if this string is
+ * lexicographically greater than the string argument.
+ */
+ public static function compareTo(str1:String, str2:String):int {
+ if (str1 == null) {
+ str1 = "";
+ }
+
+ if (str2 == null) {
+ str2 = "";
+ }
+ return str1.localeCompare(str2);
+ }
+
+ /**
+ * Adds/inserts a new string at a certain position in the source string.
+ */
+ public static function addAt(string:String, value:*, position:int):String {
+ if (position > string.length) {
+ position = string.length;
+ }
+ var firstPart:String = string.substring(0, position);
+ var secondPart:String = string.substring(position, string.length);
+ return (firstPart + value + secondPart);
+ }
+
+ /**
+ * Replaces a part of the text between 2 positions.
+ */
+ public static function replaceAt(string:String, value:*, beginIndex:int, endIndex:int):String {
+ beginIndex = Math.max(beginIndex, 0);
+ endIndex = Math.min(endIndex, string.length);
+ var firstPart:String = string.substr(0, beginIndex);
+ var secondPart:String = string.substr(endIndex, string.length);
+ return (firstPart + value + secondPart);
+ }
+
+ /**
+ * Removes a part of the text between 2 positions.
+ */
+ public static function removeAt(string:String, beginIndex:int, endIndex:int):String {
+ return StringUtils.replaceAt(string, "", beginIndex, endIndex);
+ }
+
+ /**
+ * Fixes double newlines in a text.
+ */
+ public static function fixNewlines(string:String):String {
+ return string.replace(/\r\n/gm, "\n");
+ }
+
+ /**
+ * Checks if the given string has actual text.
+ */
+ public static function hasText(string:String):Boolean {
+ if (!string)
+ return false;
+ return (StringUtils.trim(string).length > 0);
+ }
+
+ /**
+ * Removes all empty characters at the beginning of a string.
+ *
+ * <p>Characters that are removed: spaces {@code " "}, line forwards {@code "\n"}
+ * and extended line forwarding {@code "\t\n"}.
+ *
+ * @param string the string to trim
+ * @return the trimmed string
+ */
+ public static function leftTrim(string:String):String {
+ return leftTrimForChars(string, "\n\t\n ");
+ }
+
+ /**
+ * Removes all empty characters at the end of a string.
+ *
+ * <p>Characters that are removed: spaces {@code " "}, line forwards {@code "\n"}
+ * and extended line forwarding {@code "\t\n"}.
+ *
+ * @param string the string to trim
+ * @return the trimmed string
+ */
+ public static function rightTrim(string:String):String {
+ return rightTrimForChars(string, "\n\t\n ");
+ }
+
+ /**
+ * Removes all characters at the beginning of the {@code string} that match to the
+ * set of {@code chars}.
+ *
+ * <p>This method splits all {@code chars} and removes occurencies at the beginning.
+ *
+ * <p>Example:
+ * <code>
+ * trace(StringUtil.rightTrimForChars("ymoynkeym", "ym")); // oynkeym
+ * trace(StringUtil.rightTrimForChars("monkey", "mo")); // nkey
+ * trace(StringUtil.rightTrimForChars("monkey", "om")); // nkey
+ * </code>
+ *
+ * @param string the string to trim
+ * @param chars the characters to remove from the beginning of the {@code string}
+ * @return the trimmed string
+ */
+ public static function leftTrimForChars(string:String, chars:String):String {
+ var from:Number = 0;
+ var endIndex:Number = string.length;
+
+ while (from < endIndex && chars.indexOf(string.charAt(from)) >= 0) {
+ from++;
+ }
+ return (from > 0 ? string.substr(from, endIndex) : string);
+ }
+
+ /**
+ * Removes all characters at the end of the {@code string} that match to the set of
+ * {@code chars}.
+ *
+ * <p>This method splits all {@code chars} and removes occurencies at the end.
+ *
+ * <p>Example:
+ * <code>
+ * trace(StringUtil.rightTrimForChars("ymoynkeym", "ym")); // ymoynke
+ * trace(StringUtil.rightTrimForChars("monkey***", "*y")); // monke
+ * trace(StringUtil.rightTrimForChars("monke*y**", "*y")); // monke
+ * </code>
+ *
+ * @param string the string to trim
+ * @param chars the characters to remove from the end of the {@code string}
+ * @return the trimmed string
+ */
+ public static function rightTrimForChars(string:String, chars:String):String {
+ var from:Number = 0;
+ var endIndex:Number = string.length - 1;
+
+ while (from < endIndex && chars.indexOf(string.charAt(endIndex)) >= 0) {
+ endIndex--;
+ }
+ return (endIndex >= 0 ? string.substr(from, endIndex + 1) : string);
+ }
+
+ /**
+ * Removes all characters at the beginning of the {@code string} that matches the
+ * {@code char}.
+ *
+ * <p>Example:
+ * <code>
+ * trace(StringUtil.leftTrimForChar("yyyymonkeyyyy", "y"); // monkeyyyy
+ * </code>
+ *
+ * @param string the string to trim
+ * @param char the character to remove
+ * @return the trimmed string
+ * @throws IllegalArgumentException if you try to remove more than one character
+ */
+ public static function leftTrimForChar(string:String, char:String):String {
+ if (char.length != 1) {
+ throw new IllegalArgumentError("The Second Attribute char [" + char + "] must exactly one character.");
+ }
+ return leftTrimForChars(string, char);
+ }
+
+ /**
+ * Removes all characters at the end of the {@code string} that matches the passed-in
+ * {@code char}.
+ *
+ * <p>Example:
+ * <code>
+ * trace(StringUtil.rightTrimForChar("yyyymonkeyyyy", "y"); // yyyymonke
+ * </code>
+ *
+ * @param string the string to trim
+ * @param char the character to remove
+ * @return the trimmed string
+ * @throws IllegalArgumentException if you try to remove more than one character
+ */
+ public static function rightTrimForChar(string:String, char:String):String {
+ if (char.length != 1) {
+ throw new IllegalArgumentError("The Second Attribute char [" + char + "] must exactly one character.");
+ }
+ return rightTrimForChars(string, char);
+ }
+
+ /**
+ * Extended String::indexOf
+ *
+ * @param haystack string to search in
+ * @param n which ocurance of needle
+ * @param needle The substring for which to search
+ * @param startIndex An optional integer specifying the starting index of the search.
+ * @returns startIndex if n is 0
+ * @returns -1 if not enough ocurances of needle are found
+ * @returns charIndex of nth needle ocurances
+ */
+ public static function nthIndexOf(haystack:String, n:uint, needle:String, startIndex:Number = 0):int {
+ var result:int = startIndex;
+
+ if (n >= 1) {
+ result = haystack.indexOf(needle, result);
+
+ for (var i:int = 1; result != -1 && i < n; i++) {
+ result = haystack.indexOf(needle, result + 1);
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Returns if the given character is a white space or not.
+ */
+ public static function characterIsWhitespace(a:String):Boolean {
+ return (a.charCodeAt(0) <= 32);
+ }
+
+ /**
+ * Returns if the given character is a digit or not.
+ */
+ public static function characterIsDigit(a:String):Boolean {
+ var charCode:Number = a.charCodeAt(0);
+ return (charCode >= 48 && charCode <= 57);
+ }
+
+ /**
+ * Natural sort order compare function.
+ *
+ * @ignore Based on the JavaScript version by Kristof Coomans.
+ * (http://sourcefrog.net/projects/natsort/natcompare.js)
+ */
+ public static function naturalCompare(a:String, b:String):int { // NO PMD TooLongFunction
+ var iaa:int = 0, ibb:int = 0;
+ var nza:int = 0, nzb:int = 0;
+ var caa:String, cbb:String;
+ var result:int;
+ var lowerCaseBeforeUpperCase:Boolean = true; // used to be a method argument, keep this
+
+ // replace null values with empty strings
+ if (!a)
+ a = "";
+
+ if (!b)
+ b = "";
+
+ /*if (!caseSensitive) {
+ a = a.toLowerCase();
+ b = b.toLowerCase();
+ }*/
+
+ var stringsAreCaseInsensitiveEqual:Boolean = false;
+
+ if (a.toLocaleLowerCase() == b.toLocaleLowerCase()) {
+ stringsAreCaseInsensitiveEqual = true;
+ } else {
+ a = a.toLowerCase();
+ b = b.toLowerCase();
+ }
+
+ while (true) {
+ // only count the number of zeroes leading the last number compared
+ nza = nzb = 0;
+
+ caa = a.charAt(iaa);
+ cbb = b.charAt(ibb);
+
+ // skip over leading spaces or zeros
+ while (StringUtils.characterIsWhitespace(caa) || caa == "0") {
+ if (caa == "0") {
+ nza++;
+ } else {
+ // only count consecutive zeroes
+ nza = 0;
+ }
+
+ caa = a.charAt(++iaa);
+ }
+
+ while (StringUtils.characterIsWhitespace(cbb) || cbb == "0") {
+ if (cbb == "0") {
+ nzb++;
+ } else {
+ // only count consecutive zeroes
+ nzb = 0;
+ }
+
+ cbb = b.charAt(++ibb);
+ }
+
+ // process run of digits
+ if (StringUtils.characterIsDigit(caa) && StringUtils.characterIsDigit(cbb)) {
+ if ((result = compareRight(a.substring(iaa), b.substring(ibb))) != 0) {
+ return result;
+ }
+ }
+
+ if (caa == "" && cbb == "") {
+ // The strings compare the same. Perhaps the caller
+ // will want to call strcmp to break the tie.
+ return nza - nzb;
+ }
+
+ if (stringsAreCaseInsensitiveEqual) {
+ // If the characters are in another case (upper or lower)
+ if (caa != cbb) {
+ if (caa < cbb) { // NO PMD DeeplyNestedIf
+ return lowerCaseBeforeUpperCase ? +1 : -1;
+ } else if (caa > cbb) {
+ return lowerCaseBeforeUpperCase ? -1 : +1;
+ }
+ }
+ }
+
+ if (caa < cbb) {
+ return -1;
+ } else if (caa > cbb) {
+ return +1;
+ }
+
+ ++iaa;
+ ++ibb;
+ }
+
+ return 0;
+ }
+
+ /**
+ * Helper function used by the naturalCompare method.
+ */
+ private static function compareRight(a:String, b:String):int {
+ var bias:int = 0;
+ var iaa:int = 0;
+ var ibb:int = 0;
+ var caa:String;
+ var cbb:String;
+
+ // The longest run of digits wins. That aside, the greatest
+ // value wins, but we can't know that it will until we've scanned
+ // both numbers to know that they have the same magnitude, so we
+ // remember it in BIAS.
+ for (; ; iaa++, ibb++) {
+ caa = a.charAt(iaa);
+ cbb = b.charAt(ibb);
+
+ if (!StringUtils.characterIsDigit(caa) && !StringUtils.characterIsDigit(cbb)) {
+ return bias;
+ } else if (!StringUtils.characterIsDigit(caa)) {
+ return -1;
+ } else if (!StringUtils.characterIsDigit(cbb)) {
+ return +1;
+ } else if (caa < cbb) {
+ if (bias == 0) {
+ bias = -1;
+ }
+ } else if (caa > cbb) {
+ if (bias == 0)
+ bias = +1;
+ } else if (caa == "" && cbb == "") {
+ return bias;
+ }
+ }
+
+ return 0;
+ }
+
+ /**
+ * Tokenizes a string to an array using the given delimiters.
+ */
+ public static function tokenizeToArray(string:String, delimiters:String):Array {
+ var result:Array = [];
+ var numCharacters:int = string.length;
+ var delimiterFound:Boolean = false; // NO PMD UnusedLocalVariable
+ var token:String = "";
+
+ for (var i:int = 0; i < numCharacters; i++) {
+ var character:String = string.charAt(i);
+
+ if (delimiters.indexOf(character) == -1) {
+ token += character;
+ } else {
+ result.push(token);
+ token = "";
+ }
+
+ // add the last token if we reached the end of the string
+ if (i == numCharacters - 1) {
+ result.push(token);
+ }
+ }
+
+ return result;
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/FlexPMD232.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/FlexPMD232.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/FlexPMD232.as
new file mode 100644
index 0000000..571c278
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/FlexPMD232.as
@@ -0,0 +1,36 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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 src.live ;
+{
+ class LiveRecording13
+ {
+ public function recordNoCheckTimeShifting(program:EpgProgramShort, epgDay:EpgDay, channelNumber:Number):Void
+ {
+ if (channelNumber != Zapping.getInstance().getCurrentLCN() &&
+ ( (aPossibilities.length == 0)
+ || /* Shouldn't be necessery to test because of getTheBestPossibleUriToRecord() */
+ !EligibigityConflictController.getInstance().canRecordWhileDisplaying(uriToRecord, videoDefToRecord)
+ )
+ )
+ {
+ return ;
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/FlexPMD233a.mxml
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/FlexPMD233a.mxml b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/FlexPMD233a.mxml
new file mode 100644
index 0000000..58026d1
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/FlexPMD233a.mxml
@@ -0,0 +1,91 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+
+ 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.
+
+-->
+<!--- The default skin class for a Spark SkinnableContainer container.
+
+ @see spark.components.SkinnableContainer
+
+ @langversion 3.0
+ @playerversion Flash 10
+ @playerversion AIR 1.5
+ @productversion Flex 4
+-->
+<s:Skin xmlns:fx="http://ns.adobe.com/mxml/2009"
+ xmlns:s="library://ns.adobe.com/flex/spark"
+ xmlns:fb="http://ns.adobe.com/flashbuilder/2009"
+ alpha.disabled="0.5">
+
+ <fx:Metadata>[HostComponent("spark.components.SkinnableContainer")]</fx:Metadata>
+
+ <s:states>
+ <s:State name="normal"/>
+ <s:State name="disabled"/>
+ </s:states>
+
+ <!--- Defines the appearance of the SkinnableContainer class's background. -->
+ <s:Rect id="background"
+ left="0"
+ right="0"
+ top="0"
+ bottom="0"
+ radiusX="4"
+ radiusY="4">
+
+ <s:stroke>
+ <!--<s:LinearGradientStroke weight="1"
+ scaleMode="normal"/>-->
+ <s:SolidColorStroke weight="1"
+ color="0xffffff"
+ scaleMode="normal"
+ alpha="0"/>
+ </s:stroke>
+
+ <s:fill>
+ <s:LinearGradient rotation="90">
+ <s:GradientEntry color="0x70a6d2"
+ alpha="1"/>
+ <!--000000 / 0.01-->
+ <s:GradientEntry color="0xdbecfb"
+ alpha="1"/>
+ <!--000000 / 0.07-->
+ </s:LinearGradient>
+
+ </s:fill>
+
+ </s:Rect>
+
+ <!--
+ Note: setting the minimum size to 0 here so that changes to the host component's
+ size will not be thwarted by this skin part's minimum size. This is a compromise,
+ more about it here: http://bugs.adobe.com/jira/browse/SDK-21143
+ -->
+ <!--- @copy spark.components.SkinnableContainer#contentGroup -->
+ <s:Group id="contentGroup"
+ left="10"
+ right="10"
+ top="0"
+ bottom="0"
+ minWidth="0"
+ minHeight="0">
+ <s:layout>
+ <s:BasicLayout/>
+ </s:layout>
+ </s:Group>
+
+</s:Skin>
[19/24] git commit: [flex-utilities]
[refs/heads/feature/pmd-5.2-language-module] - Initial commit of the PMD
language module for Apache Flex
Posted by cd...@apache.org.
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/test/resources/examples/JPEGEncoder2.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/parser/parser-impl/src/test/resources/examples/JPEGEncoder2.as b/FlexPMD/language-module/parser/parser-impl/src/test/resources/examples/JPEGEncoder2.as
new file mode 100644
index 0000000..3bcf7d1
--- /dev/null
+++ b/FlexPMD/language-module/parser/parser-impl/src/test/resources/examples/JPEGEncoder2.as
@@ -0,0 +1,671 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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
+{
+ import flash.display.BitmapData;
+ import flash.utils.ByteArray;
+
+ public final class JPEGEncoder
+ {
+ // Static table initialization
+ private const ZigZag:Vector.<int> = Vector.<int>([
+ 0, 1, 5, 6,14,15,27,28,
+ 2, 4, 7,13,16,26,29,42,
+ 3, 8,12,17,25,30,41,43,
+ 9,11,18,24,31,40,44,53,
+ 10,19,23,32,39,45,52,54,
+ 20,22,33,38,46,51,55,60,
+ 21,34,37,47,50,56,59,61,
+ 35,36,48,49,57,58,62,63
+ ]);
+ private var a:Vector.<String> = new Vector.<String>();
+ private var YTable:Vector.<int> = new Vector.<int>(64, true);
+ private var UVTable:Vector.<int> = new Vector.<int>(64, true);
+ private var outputfDCTQuant:Vector.<int> = new Vector.<int>(64, true);
+ private var fdtbl_Y:Vector.<Number> = new Vector.<Number>(64, true);
+ private var fdtbl_UV:Vector.<Number> = new Vector.<Number>(64, true);
+ private var sf:int;
+
+ private const aasf:Vector.<Number> = Vector.<Number>([
+ 1.0, 1.387039845, 1.306562965, 1.175875602,
+ 1.0, 0.785694958, 0.541196100, 0.275899379
+ ]);
+
+ private var YQT:Vector.<int> = Vector.<int>([
+ 16, 11, 10, 16, 24, 40, 51, 61,
+ 12, 12, 14, 19, 26, 58, 60, 55,
+ 14, 13, 16, 24, 40, 57, 69, 56,
+ 14, 17, 22, 29, 51, 87, 80, 62,
+ 18, 22, 37, 56, 68,109,103, 77,
+ 24, 35, 55, 64, 81,104,113, 92,
+ 49, 64, 78, 87,103,121,120,101,
+ 72, 92, 95, 98,112,100,103, 99
+ ]);
+
+ private const UVQT:Vector.<int> = Vector.<int>([
+ 17, 18, 24, 47, 99, 99, 99, 99,
+ 18, 21, 26, 66, 99, 99, 99, 99,
+ 24, 26, 56, 99, 99, 99, 99, 99,
+ 47, 66, 99, 99, 99, 99, 99, 99,
+ 99, 99, 99, 99, 99, 99, 99, 99,
+ 99, 99, 99, 99, 99, 99, 99, 99,
+ 99, 99, 99, 99, 99, 99, 99, 99,
+ 99, 99, 99, 99, 99, 99, 99, 99
+ ]);
+
+ private function initQuantTables(sf:int):void
+ {
+ var a:Vector.<String> = new Vector.<String>();
+ var i:int;
+ const I64:int = 64;
+ const I8:int = 8;
+ for (i = 0; i < I64; ++i)
+ {
+ var t:int = int((YQT[i]*sf+50)*0.01);
+ if (t < 1) {
+ t = 1;
+ } else if (t > 255) {
+ t = 255;
+ }
+ YTable[ZigZag[i]] = t;
+ }
+
+ for (i = 0; i < I64; i++)
+ {
+ var u:int = int((UVQT[i]*sf+50)*0.01);
+ if (u < 1) {
+ u = 1;
+ } else if (u > 255) {
+ u = 255;
+ }
+ UVTable[ZigZag[i]] = u;
+ }
+ i = 0;
+ for (var row:int = 0; row < I8; ++row)
+ {
+ for (var col:int = 0; col < I8; ++col)
+ {
+ fdtbl_Y[i] = (1 / (YTable [ZigZag[i]] * aasf[row] * aasf[col] * I8));
+ fdtbl_UV[i] = (1 / (UVTable[ZigZag[i]] * aasf[row] * aasf[col] * I8));
+ i++;
+ }
+ }
+ }
+
+ private var YDC_HT:Vector.<BitString>;
+ private var UVDC_HT:Vector.<BitString>;
+ private var YAC_HT:Vector.<BitString>;
+ private var UVAC_HT:Vector.<BitString>;
+
+ private function computeHuffmanTbl(nrcodes:Vector.<int>, std_table:Vector.<int>):Vector.<BitString>
+ {
+ var codevalue:int = 0;
+ var pos_in_table:int = 0;
+ var HT:Vector.<BitString> = new Vector.<BitString>(251, true);
+ var bitString:BitString;
+ for (var k:int=1; k<=16; ++k)
+ {
+ for (var j:int=1; j<=nrcodes[k]; ++j)
+ {
+ HT[std_table[pos_in_table]] = bitString = new BitString();
+ bitString.val = codevalue;
+ bitString.len = k;
+ pos_in_table++;
+ codevalue++;
+ }
+ codevalue<<=1;
+ }
+ return HT;
+ }
+
+ private var std_dc_luminance_nrcodes:Vector.<int> = Vector.<int>([0,0,1,5,1,1,1,1,1,1,0,0,0,0,0,0,0]);
+ private var std_dc_luminance_values:Vector.<int> = Vector.<int>([0,1,2,3,4,5,6,7,8,9,10,11]);
+ private var std_ac_luminance_nrcodes:Vector.<int> = Vector.<int>([0,0,2,1,3,3,2,4,3,5,5,4,4,0,0,1,0x7d]);
+ private var std_ac_luminance_values:Vector.<int> = Vector.<int>([0x01,0x02,0x03,0x00,0x04,0x11,0x05,0x12,
+ 0x21,0x31,0x41,0x06,0x13,0x51,0x61,0x07,
+ 0x22,0x71,0x14,0x32,0x81,0x91,0xa1,0x08,
+ 0x23,0x42,0xb1,0xc1,0x15,0x52,0xd1,0xf0,
+ 0x24,0x33,0x62,0x72,0x82,0x09,0x0a,0x16,
+ 0x17,0x18,0x19,0x1a,0x25,0x26,0x27,0x28,
+ 0x29,0x2a,0x34,0x35,0x36,0x37,0x38,0x39,
+ 0x3a,0x43,0x44,0x45,0x46,0x47,0x48,0x49,
+ 0x4a,0x53,0x54,0x55,0x56,0x57,0x58,0x59,
+ 0x5a,0x63,0x64,0x65,0x66,0x67,0x68,0x69,
+ 0x6a,0x73,0x74,0x75,0x76,0x77,0x78,0x79,
+ 0x7a,0x83,0x84,0x85,0x86,0x87,0x88,0x89,
+ 0x8a,0x92,0x93,0x94,0x95,0x96,0x97,0x98,
+ 0x99,0x9a,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,
+ 0xa8,0xa9,0xaa,0xb2,0xb3,0xb4,0xb5,0xb6,
+ 0xb7,0xb8,0xb9,0xba,0xc2,0xc3,0xc4,0xc5,
+ 0xc6,0xc7,0xc8,0xc9,0xca,0xd2,0xd3,0xd4,
+ 0xd5,0xd6,0xd7,0xd8,0xd9,0xda,0xe1,0xe2,
+ 0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0xea,
+ 0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,
+ 0xf9,0xfa]);
+
+ private var std_dc_chrominance_nrcodes:Vector.<int> = Vector.<int>([0,0,3,1,1,1,1,1,1,1,1,1,0,0,0,0,0]);
+ private var std_dc_chrominance_values:Vector.<int> = Vector.<int>([0,1,2,3,4,5,6,7,8,9,10,11]);
+ private var std_ac_chrominance_nrcodes:Vector.<int> = Vector.<int>([0,0,2,1,2,4,4,3,4,7,5,4,4,0,1,2,0x77]);
+ private var std_ac_chrominance_values:Vector.<int> = Vector.<int>([0x00,0x01,0x02,0x03,0x11,0x04,0x05,0x21,
+ 0x31,0x06,0x12,0x41,0x51,0x07,0x61,0x71,
+ 0x13,0x22,0x32,0x81,0x08,0x14,0x42,0x91,
+ 0xa1,0xb1,0xc1,0x09,0x23,0x33,0x52,0xf0,
+ 0x15,0x62,0x72,0xd1,0x0a,0x16,0x24,0x34,
+ 0xe1,0x25,0xf1,0x17,0x18,0x19,0x1a,0x26,
+ 0x27,0x28,0x29,0x2a,0x35,0x36,0x37,0x38,
+ 0x39,0x3a,0x43,0x44,0x45,0x46,0x47,0x48,
+ 0x49,0x4a,0x53,0x54,0x55,0x56,0x57,0x58,
+ 0x59,0x5a,0x63,0x64,0x65,0x66,0x67,0x68,
+ 0x69,0x6a,0x73,0x74,0x75,0x76,0x77,0x78,
+ 0x79,0x7a,0x82,0x83,0x84,0x85,0x86,0x87,
+ 0x88,0x89,0x8a,0x92,0x93,0x94,0x95,0x96,
+ 0x97,0x98,0x99,0x9a,0xa2,0xa3,0xa4,0xa5,
+ 0xa6,0xa7,0xa8,0xa9,0xaa,0xb2,0xb3,0xb4,
+ 0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xc2,0xc3,
+ 0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xd2,
+ 0xd3,0xd4,0xd5,0xd6,0xd7,0xd8,0xd9,0xda,
+ 0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,
+ 0xea,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,
+ 0xf9,0xfa
+ ]);
+
+ private function initHuffmanTbl():void
+ {
+ YDC_HT = computeHuffmanTbl(std_dc_luminance_nrcodes,std_dc_luminance_values);
+ UVDC_HT = computeHuffmanTbl(std_dc_chrominance_nrcodes,std_dc_chrominance_values);
+ YAC_HT = computeHuffmanTbl(std_ac_luminance_nrcodes,std_ac_luminance_values);
+ UVAC_HT = computeHuffmanTbl(std_ac_chrominance_nrcodes,std_ac_chrominance_values);
+ }
+
+ private var bitcode:Vector.<BitString> = new Vector.<BitString>(65535, true);
+ private var category:Vector.<int> = new Vector.<int>(65535, true);
+
+ private function initCategoryNumber():void
+ {
+ var nrlower:int = 1;
+ var nrupper:int = 2;
+ var bitString:BitString;
+ const I15:int = 15;
+ var pos:int;
+ for (var cat:int=1; cat<=I15; ++cat)
+ {
+ //Positive numbers
+ for (var nr:int=nrlower; nr<nrupper; ++nr)
+ {
+ pos = int(32767+nr);
+ category[pos] = cat;
+ bitcode[pos] = bitString = new BitString();
+ bitString.len = cat;
+ bitString.val = nr;
+ }
+ //Negative numbers
+ for (var nrneg:int=-(nrupper-1); nrneg<=-nrlower; ++nrneg)
+ {
+ pos = int(32767+nrneg);
+ category[pos] = cat;
+ bitcode[pos] = bitString = new BitString();
+ bitString.len = cat;
+ bitString.val = nrupper-1+nrneg;
+ }
+ nrlower <<= 1;
+ nrupper <<= 1;
+ }
+ }
+
+ // IO functions
+
+ private var byteout:ByteArray;
+ private var bytenew:int = 0;
+ private var bytepos:int = 7;
+
+ private function writeBits(bs:BitString):void
+ {
+ var value:int = bs.val;
+ var posval:int = bs.len-1;
+ while ( posval >= 0 )
+ {
+ if (value & uint(1 << posval) )
+ bytenew |= uint(1 << bytepos);
+ posval--;
+ bytepos--;
+ if (bytepos < 0)
+ {
+ if (bytenew == 0xFF)
+ {
+ byteout.writeByte(0xFF);
+ byteout.writeByte(0);
+ }
+ else byteout.writeByte(bytenew);
+ bytepos=7;
+ bytenew=0;
+ }
+ }
+ }
+
+ // DCT & quantization core
+
+ private function fDCTQuant(data:Vector.<Number>, fdtbl:Vector.<Number>):Vector.<int>
+ {
+ /* Pass 1: process rows. */
+ var dataOff:int=0;
+ var d0:Number, d1:Number, d2:Number, d3:Number, d4:Number, d5:Number, d6:Number, d7:Number;
+ var i:int;
+ const I8:int = 8;
+ const I64:int = 64;
+ for (i=0; i<I8; ++i)
+ {
+ d0 = data[int(dataOff)];
+ d1 = data[int(dataOff+1)];
+ d2 = data[int(dataOff+2)];
+ d3 = data[int(dataOff+3)];
+ d4 = data[int(dataOff+4)];
+ d5 = data[int(dataOff+5)];
+ d6 = data[int(dataOff+6)];
+ d7 = data[int(dataOff+7)];
+
+ var tmp0:Number = d0 + d7;
+ var tmp7:Number = d0 - d7;
+ var tmp1:Number = d1 + d6;
+ var tmp6:Number = d1 - d6;
+ var tmp2:Number = d2 + d5;
+ var tmp5:Number = d2 - d5;
+ var tmp3:Number = d3 + d4;
+ var tmp4:Number = d3 - d4;
+
+ /* Even part */
+ var tmp10:Number = tmp0 + tmp3; /* phase 2 */
+ var tmp13:Number = tmp0 - tmp3;
+ var tmp11:Number = tmp1 + tmp2;
+ var tmp12:Number = tmp1 - tmp2;
+
+ data[int(dataOff)] = tmp10 + tmp11; /* phase 3 */
+ data[int(dataOff+4)] = tmp10 - tmp11;
+
+ var z1:Number = (tmp12 + tmp13) * 0.707106781; /* c4 */
+ data[int(dataOff+2)] = tmp13 + z1; /* phase 5 */
+ data[int(dataOff+6)] = tmp13 - z1;
+
+ /* Odd part */
+ tmp10 = tmp4 + tmp5; /* phase 2 */
+ tmp11 = tmp5 + tmp6;
+ tmp12 = tmp6 + tmp7;
+
+ /* The rotator is modified from fig 4-8 to avoid extra negations. */
+ var z5:Number = (tmp10 - tmp12) * 0.382683433; /* c6 */
+ var z2:Number = 0.541196100 * tmp10 + z5; /* c2-c6 */
+ var z4:Number = 1.306562965 * tmp12 + z5; /* c2+c6 */
+ var z3:Number = tmp11 * 0.707106781; /* c4 */
+
+ var z11:Number = tmp7 + z3; /* phase 5 */
+ var z13:Number = tmp7 - z3;
+
+ data[int(dataOff+5)] = z13 + z2; /* phase 6 */
+ data[int(dataOff+3)] = z13 - z2;
+ data[int(dataOff+1)] = z11 + z4;
+ data[int(dataOff+7)] = z11 - z4;
+
+ dataOff += 8; /* advance pointer to next row */
+ }
+
+ /* Pass 2: process columns. */
+ dataOff = 0;
+ for (i=0; i<I8; ++i)
+ {
+ d0 = data[int(dataOff)];
+ d1 = data[int(dataOff + 8)];
+ d2 = data[int(dataOff + 16)];
+ d3 = data[int(dataOff + 24)];
+ d4 = data[int(dataOff + 32)];
+ d5 = data[int(dataOff + 40)];
+ d6 = data[int(dataOff + 48)];
+ d7 = data[int(dataOff + 56)];
+
+ var tmp0p2:Number = d0 + d7;
+ var tmp7p2:Number = d0 - d7;
+ var tmp1p2:Number = d1 + d6;
+ var tmp6p2:Number = d1 - d6;
+ var tmp2p2:Number = d2 + d5;
+ var tmp5p2:Number = d2 - d5;
+ var tmp3p2:Number = d3 + d4;
+ var tmp4p2:Number = d3 - d4;
+
+ /* Even part */
+ var tmp10p2:Number = tmp0p2 + tmp3p2; /* phase 2 */
+ var tmp13p2:Number = tmp0p2 - tmp3p2;
+ var tmp11p2:Number = tmp1p2 + tmp2p2;
+ var tmp12p2:Number = tmp1p2 - tmp2p2;
+
+ data[int(dataOff)] = tmp10p2 + tmp11p2; /* phase 3 */
+ data[int(dataOff+32)] = tmp10p2 - tmp11p2;
+
+ var z1p2:Number = (tmp12p2 + tmp13p2) * 0.707106781; /* c4 */
+ data[int(dataOff+16)] = tmp13p2 + z1p2; /* phase 5 */
+ data[int(dataOff+48)] = tmp13p2 - z1p2;
+
+ /* Odd part */
+ tmp10p2 = tmp4p2 + tmp5p2; /* phase 2 */
+ tmp11p2 = tmp5p2 + tmp6p2;
+ tmp12p2 = tmp6p2 + tmp7p2;
+
+ /* The rotator is modified from fig 4-8 to avoid extra negations. */
+ var z5p2:Number = (tmp10p2 - tmp12p2) * 0.382683433; /* c6 */
+ var z2p2:Number = 0.541196100 * tmp10p2 + z5p2; /* c2-c6 */
+ var z4p2:Number = 1.306562965 * tmp12p2 + z5p2; /* c2+c6 */
+ var z3p2:Number= tmp11p2 * 0.707106781; /* c4 */
+
+ var z11p2:Number = tmp7p2 + z3p2; /* phase 5 */
+ var z13p2:Number = tmp7p2 - z3p2;
+
+ data[int(dataOff+40)] = z13p2 + z2p2; /* phase 6 */
+ data[int(dataOff+24)] = z13p2 - z2p2;
+ data[int(dataOff+ 8)] = z11p2 + z4p2;
+ data[int(dataOff+56)] = z11p2 - z4p2;
+
+ dataOff++; /* advance pointer to next column */
+ }
+
+ // Quantize/descale the coefficients
+ var fDCTQuant:Number;
+ for (i=0; i<I64; ++i)
+ {
+ // Apply the quantization and scaling factor & Round to nearest integer
+ fDCTQuant = data[int(i)]*fdtbl[int(i)];
+ outputfDCTQuant[int(i)] = (fDCTQuant > 0.0) ? int(fDCTQuant + 0.5) : int(fDCTQuant - 0.5);
+ }
+ return outputfDCTQuant;
+ }
+
+ // Chunk writing
+ private function writeAPP0():void
+ {
+ byteout.writeShort(0xFFE0); // marker
+ byteout.writeShort(16); // length
+ byteout.writeByte(0x4A); // J
+ byteout.writeByte(0x46); // F
+ byteout.writeByte(0x49); // I
+ byteout.writeByte(0x46); // F
+ byteout.writeByte(0); // = "JFIF",'\0'
+ byteout.writeByte(1); // versionhi
+ byteout.writeByte(1); // versionlo
+ byteout.writeByte(0); // xyunits
+ byteout.writeShort(1); // xdensity
+ byteout.writeShort(1); // ydensity
+ byteout.writeByte(0); // thumbnwidth
+ byteout.writeByte(0); // thumbnheight
+ }
+
+ private function writeSOF0(width:int, height:int):void
+ {
+ byteout.writeShort(0xFFC0); // marker
+ byteout.writeShort(17); // length, truecolor YUV JPG
+ byteout.writeByte(8); // precision
+ byteout.writeShort(height);
+ byteout.writeShort(width);
+ byteout.writeByte(3); // nrofcomponents
+ byteout.writeByte(1); // IdY
+ byteout.writeByte(0x11); // HVY
+ byteout.writeByte(0); // QTY
+ byteout.writeByte(2); // IdU
+ byteout.writeByte(0x11); // HVU
+ byteout.writeByte(1); // QTU
+ byteout.writeByte(3); // IdV
+ byteout.writeByte(0x11); // HVV
+ byteout.writeByte(1); // QTV
+ }
+
+ private function writeDQT():void
+ {
+ byteout.writeShort(0xFFDB); // marker
+ byteout.writeShort(132); // length
+ byteout.writeByte(0);
+
+ var i:int;
+ const I64:int = 64;
+ for (i=0; i<I64; ++i)
+ byteout.writeByte(YTable[i]);
+
+ byteout.writeByte(1);
+
+ for (i=0; i<I64; ++i)
+ byteout.writeByte(UVTable[i]);
+ }
+
+ private function writeDHT():void
+ {
+ byteout.writeShort(0xFFC4); // marker
+ byteout.writeShort(0x01A2); // length
+
+ byteout.writeByte(0); // HTYDCinfo
+ var i:int;
+ const I11:int = 11;
+ const I16:int = 16;
+ const I161:int = 161;
+ for (i=0; i<I16; ++i)
+ byteout.writeByte(std_dc_luminance_nrcodes[int(i+1)]);
+
+ for (i=0; i<=I11; ++i)
+ byteout.writeByte(std_dc_luminance_values[int(i)]);
+
+ byteout.writeByte(0x10); // HTYACinfo
+
+ for (i=0; i<I16; ++i)
+ byteout.writeByte(std_ac_luminance_nrcodes[int(i+1)]);
+
+ for (i=0; i<=I161; ++i)
+ byteout.writeByte(std_ac_luminance_values[int(i)]);
+
+ byteout.writeByte(1); // HTUDCinfo
+
+ for (i=0; i<I16; ++i)
+ byteout.writeByte(std_dc_chrominance_nrcodes[int(i+1)]);
+
+ for (i=0; i<=I11; ++i)
+ byteout.writeByte(std_dc_chrominance_values[int(i)]);
+
+ byteout.writeByte(0x11); // HTUACinfo
+
+ for (i=0; i<I16; ++i)
+ byteout.writeByte(std_ac_chrominance_nrcodes[int(i+1)]);
+
+ for (i=0; i<=I161; ++i)
+ byteout.writeByte(std_ac_chrominance_values[int(i)]);
+ }
+
+ private function writeSOS():void
+ {
+ byteout.writeShort(0xFFDA); // marker
+ byteout.writeShort(12); // length
+ byteout.writeByte(3); // nrofcomponents
+ byteout.writeByte(1); // IdY
+ byteout.writeByte(0); // HTY
+ byteout.writeByte(2); // IdU
+ byteout.writeByte(0x11); // HTU
+ byteout.writeByte(3); // IdV
+ byteout.writeByte(0x11); // HTV
+ byteout.writeByte(0); // Ss
+ byteout.writeByte(0x3f); // Se
+ byteout.writeByte(0); // Bf
+ }
+
+ // Core processing
+ internal var DU:Vector.<int> = new Vector.<int>(64, true);
+
+ private function processDU(CDU:Vector.<Number>, fdtbl:Vector.<Number>, DC:Number, HTDC:Vector.<BitString>, HTAC:Vector.<BitString>):Number
+ {
+ var EOB:BitString = HTAC[0x00];
+ var M16zeroes:BitString = HTAC[0xF0];
+ var pos:int;
+ const I16:int = 16;
+ const I63:int = 63;
+ const I64:int = 64;
+ var DU_DCT:Vector.<int> = fDCTQuant(CDU, fdtbl);
+ //ZigZag reorder
+ for (var j:int=0;j<I64;++j) {
+ DU[ZigZag[j]]=DU_DCT[j];
+ }
+ var Diff:int = DU[0] - DC; DC = DU[0];
+ //Encode DC
+ if (Diff==0) {
+ writeBits(HTDC[0]); // Diff might be 0
+ } else {
+ pos = int(32767+Diff);
+ writeBits(HTDC[category[pos]]);
+ writeBits(bitcode[pos]);
+ }
+ //Encode ACs
+ const end0pos:int = 63;
+ for (; (end0pos>0)&&(DU[end0pos]==0); end0pos--) {};
+ //end0pos = first element in reverse order !=0
+ if ( end0pos == 0) {
+ writeBits(EOB);
+ return DC;
+ }
+ var i:int = 1;
+ var lng:int;
+ while ( i <= end0pos ) {
+ var startpos:int = i;
+ for (; (DU[i]==0) && (i<=end0pos); ++i) {}
+ var nrzeroes:int = i-startpos;
+ if ( nrzeroes >= I16 ) {
+ lng = nrzeroes>>4;
+ for (var nrmarker:int=1; nrmarker <= lng; ++nrmarker)
+ writeBits(M16zeroes);
+ nrzeroes = int(nrzeroes&0xF);
+ }
+ pos = int(32767+DU[i]);
+ writeBits(HTAC[int((nrzeroes<<4)+category[pos])]);
+ writeBits(bitcode[pos]);
+ i++;
+ }
+ if ( end0pos != I63 ) {
+ writeBits(EOB);
+ }
+ return DC;
+ }
+
+ private var YDU:Vector.<Number> = new Vector.<Number>(64, true);
+ private var UDU:Vector.<Number> = new Vector.<Number>(64, true);
+ private var VDU:Vector.<Number> = new Vector.<Number>(64, true);
+
+ private function RGB2YUV(img:BitmapData, xpos:int, ypos:int):void
+ {
+ var pos:int=0;
+ const I8:int = 8;
+ for (var y:int=0; y<I8; ++y) {
+ for (var x:int=0; x<I8; ++x) {
+ var P:uint = img.getPixel32(xpos+x,ypos+y);
+ var R:int = (P>>16)&0xFF;
+ var G:int = (P>> 8)&0xFF;
+ var B:int = (P )&0xFF;
+ YDU[int(pos)]=((( 0.29900)*R+( 0.58700)*G+( 0.11400)*B))-0x80;
+ UDU[int(pos)]=(((-0.16874)*R+(-0.33126)*G+( 0.50000)*B));
+ VDU[int(pos)]=((( 0.50000)*R+(-0.41869)*G+(-0.08131)*B));
+ ++pos;
+ }
+ }
+ }
+
+ public function JPEGEncoder(quality:int=50)
+ {
+ if (quality <= 0)
+ quality = 1;
+
+ if (quality > 100)
+ quality = 100;
+
+ sf = quality < 50 ? int(5000 / quality) : int(200 - (quality<<1));
+ init();
+ }
+
+ private function init():void
+ {
+ ZigZag.fixed = true;
+ aasf.fixed = true;
+ YQT.fixed = true;
+ UVQT.fixed = true;
+ std_ac_chrominance_nrcodes.fixed = true;
+ std_ac_chrominance_values.fixed = true;
+ std_ac_luminance_nrcodes.fixed = true;
+ std_ac_luminance_values.fixed = true;
+ std_dc_chrominance_nrcodes.fixed = true;
+ std_dc_chrominance_values.fixed = true;
+ std_dc_luminance_nrcodes.fixed = true;
+ std_dc_luminance_values.fixed = true;
+ // Create tables
+ initHuffmanTbl();
+ initCategoryNumber();
+ initQuantTables(sf);
+ }
+
+ public function encode(image:BitmapData):ByteArray
+ {
+ // Initialize bit writer
+ byteout = new ByteArray();
+
+ bytenew=0;
+ bytepos=7;
+
+ // Add JPEG headers
+ byteout.writeShort(0xFFD8); // SOI
+ writeAPP0();
+ writeDQT();
+ writeSOF0(image.width,image.height);
+ writeDHT();
+ writeSOS();
+
+ // Encode 8x8 macroblocks
+ var DCY:Number=0;
+ var DCU:Number=0;
+ var DCV:Number=0;
+ bytenew=0;
+ bytepos=7;
+
+ var width:int = image.width;
+ var height:int = image.height;
+
+ for (var ypos:int=0; ypos<height; ypos+=8)
+ {
+ for (var xpos:int=0; xpos<width; xpos+=8)
+ {
+ RGB2YUV(image, xpos, ypos);
+ DCY = processDU(YDU, fdtbl_Y, DCY, YDC_HT, YAC_HT);
+ DCU = processDU(UDU, fdtbl_UV, DCU, UVDC_HT, UVAC_HT);
+ DCV = processDU(VDU, fdtbl_UV, DCV, UVDC_HT, UVAC_HT);
+ }
+ }
+
+ // Do the bit alignment of the EOI marker
+ if ( bytepos >= 0 )
+ {
+ var fillbits:BitString = new BitString();
+ fillbits.len = bytepos+1;
+ fillbits.val = (1<<(bytepos+1))-1;
+ writeBits(fillbits);
+ }
+ byteout.writeShort(0xFFD9); //EOI
+ return byteout;
+ }
+ }
+}
+
+final class BitString
+{
+ public var len:int = 0;
+ public var val:int = 0;
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/test/resources/examples/toAS2/src/fw/data/request/ResultListener.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/parser/parser-impl/src/test/resources/examples/toAS2/src/fw/data/request/ResultListener.as b/FlexPMD/language-module/parser/parser-impl/src/test/resources/examples/toAS2/src/fw/data/request/ResultListener.as
new file mode 100644
index 0000000..f225da6
--- /dev/null
+++ b/FlexPMD/language-module/parser/parser-impl/src/test/resources/examples/toAS2/src/fw/data/request/ResultListener.as
@@ -0,0 +1,27 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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.
+//
+////////////////////////////////////////////////////////////////////////////////
+
+import src.fw.data.request.Request;
+interface src.fw.data.request.ResultListener
+{
+ public function onResultLoad(request:Request) : Void;
+
+ public function onResultError(request:Request) : Void;
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/test/resources/examples/unformatted/IContext.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/parser/parser-impl/src/test/resources/examples/unformatted/IContext.as b/FlexPMD/language-module/parser/parser-impl/src/test/resources/examples/unformatted/IContext.as
new file mode 100644
index 0000000..ee1fe67
--- /dev/null
+++ b/FlexPMD/language-module/parser/parser-impl/src/test/resources/examples/unformatted/IContext.as
@@ -0,0 +1,83 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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.commons.context
+{
+ import flash.events.IEventDispatcher;
+
+ /**
+ * Interface IContext.
+ *
+ * @author (resp. mv)
+ */
+ public interface IContext extends IEventDispatcher
+ {
+
+ /**
+ * Get Value for given key.
+ * All contexts are searched for the given key.
+ *
+ * @param key the name of the attribute to search.
+ * @result the found value for given key or null.
+ */
+ function getValue(key:String) : Object;
+
+ /**
+ * Put a value into the context for a given key.
+ *
+ * @param key the key to store this object.
+ * @param value the value of the given key.
+ */
+ function putValue(key:String, value:Object) : void;
+
+ /**
+ * Get the context of given type.
+ *
+ * @param contextType the type of the context.
+ * @result the context of the given type or null.
+ */
+ function getContext(contextType:String) : IContext;
+
+ /**
+ * Get the owner of this context.
+ * @return the owner, if there is one, or null.
+ */
+ [Deprecated("There is no owner any longer. Do not use this property")]
+ function get owner() : IContextOwner;
+
+ /**
+ * Parent context. (e.g. for managing "shared" resources).
+ * All contextes build a tree. With this getter you get the parent of this context inside the tree.
+ */
+ function get parentContext() : IContext;
+
+ /**
+ * Get the resource for given url.
+ * @param key the url or key of the asset.
+ * @return the object of given url with following type:
+ * MediaType.Text := String
+ * MediaType.Audio := com.commons.media.ISound
+ * MediaType.Image := DisplayObject
+ * MediaType.FlexModule := DisplayObject
+ * MediaType.Video := NetStream
+ * MediaType.FlashApplication := DisplayObject
+ * MediaType.FlexStyleDeclaration := null
+ */
+ function getResource(key:String) : Object;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/test/resources/examples/unformatted/Simple.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/parser/parser-impl/src/test/resources/examples/unformatted/Simple.as b/FlexPMD/language-module/parser/parser-impl/src/test/resources/examples/unformatted/Simple.as
new file mode 100644
index 0000000..78bd746
--- /dev/null
+++ b/FlexPMD/language-module/parser/parser-impl/src/test/resources/examples/unformatted/Simple.as
@@ -0,0 +1,19 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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 simple { public class Simple { public function Simple ( ) { trace ( "Simple" ); } } }
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/test/resources/examples/unformatted/Title.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/parser/parser-impl/src/test/resources/examples/unformatted/Title.as b/FlexPMD/language-module/parser/parser-impl/src/test/resources/examples/unformatted/Title.as
new file mode 100644
index 0000000..e2301fb
--- /dev/null
+++ b/FlexPMD/language-module/parser/parser-impl/src/test/resources/examples/unformatted/Title.as
@@ -0,0 +1,32 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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 org.viewing
+
+{
+
+ public final class Title
+
+ {
+
+ public static const SHOW:String = "true";
+ public static const HIDE:String = "false";
+
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/pom.xml
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/parser/pom.xml b/FlexPMD/language-module/parser/pom.xml
new file mode 100755
index 0000000..1c40fdf
--- /dev/null
+++ b/FlexPMD/language-module/parser/pom.xml
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.flex.pmd</groupId>
+ <artifactId>apache-flex-pmd</artifactId>
+ <version>2.0.0-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.apache.flex.pmd.parser</groupId>
+ <artifactId>parser</artifactId>
+ <version>2.0.0-SNAPSHOT</version>
+ <packaging>pom</packaging>
+
+ <modules>
+ <module>parser-api</module>
+ <module>parser-impl</module>
+ </modules>
+
+</project>
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/pmd-flex/pom.xml
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/pmd-flex/pom.xml b/FlexPMD/language-module/pmd-flex/pom.xml
new file mode 100644
index 0000000..15e2676
--- /dev/null
+++ b/FlexPMD/language-module/pmd-flex/pom.xml
@@ -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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.flex.pmd</groupId>
+ <artifactId>apache-flex-pmd</artifactId>
+ <version>2.0.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>pmd-flex</artifactId>
+ <version>2.0.0-SNAPSHOT</version>
+ <packaging>jar</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>net.sourceforge.pmd</groupId>
+ <artifactId>pmd-core</artifactId>
+ <version>${pmd.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.flex.pmd.parser</groupId>
+ <artifactId>parser-impl</artifactId>
+ <version>2.0.0-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>net.sourceforge.pmd</groupId>
+ <artifactId>pmd-test</artifactId>
+ <version>${pmd.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/pmd-flex/src/main/java/org/apache/flex/pmd/FlexLanguageModule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/pmd-flex/src/main/java/org/apache/flex/pmd/FlexLanguageModule.java b/FlexPMD/language-module/pmd-flex/src/main/java/org/apache/flex/pmd/FlexLanguageModule.java
new file mode 100644
index 0000000..33864d9
--- /dev/null
+++ b/FlexPMD/language-module/pmd-flex/src/main/java/org/apache/flex/pmd/FlexLanguageModule.java
@@ -0,0 +1,21 @@
+package org.apache.flex.pmd;
+
+import net.sourceforge.pmd.lang.BaseLanguageModule;
+import org.apache.flex.pmd.handler.Flex4LanguageVersionHandler;
+import org.apache.flex.pmd.rule.FlexRuleChainVisitor;
+
+/**
+ * Created by christoferdutz on 06.03.15.
+ */
+public class FlexLanguageModule extends BaseLanguageModule {
+
+ public static final String NAME = "Flex";
+ public static final String TERSE_NAME = "flex";
+ public static final String DEFAULT_VERSION = "flex4";
+
+ public FlexLanguageModule() {
+ super(NAME, null, TERSE_NAME, FlexRuleChainVisitor.class, ".as", ".mxml");
+ addVersion(DEFAULT_VERSION, new Flex4LanguageVersionHandler(), true);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/pmd-flex/src/main/java/org/apache/flex/pmd/handler/Flex4LanguageVersionHandler.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/pmd-flex/src/main/java/org/apache/flex/pmd/handler/Flex4LanguageVersionHandler.java b/FlexPMD/language-module/pmd-flex/src/main/java/org/apache/flex/pmd/handler/Flex4LanguageVersionHandler.java
new file mode 100644
index 0000000..5d014fd
--- /dev/null
+++ b/FlexPMD/language-module/pmd-flex/src/main/java/org/apache/flex/pmd/handler/Flex4LanguageVersionHandler.java
@@ -0,0 +1,25 @@
+package org.apache.flex.pmd.handler;
+
+import net.sourceforge.pmd.lang.AbstractLanguageVersionHandler;
+import net.sourceforge.pmd.lang.Parser;
+import net.sourceforge.pmd.lang.ParserOptions;
+import net.sourceforge.pmd.lang.rule.RuleViolationFactory;
+import org.apache.flex.pmd.parser.impl.AS3Parser;
+import org.apache.flex.pmd.rule.FlexRuleViolationFactory;
+
+/**
+ * Created by christoferdutz on 06.03.15.
+ */
+public class Flex4LanguageVersionHandler extends AbstractLanguageVersionHandler {
+
+ @Override
+ public RuleViolationFactory getRuleViolationFactory() {
+ return FlexRuleViolationFactory.INSTANCE;
+ }
+
+ @Override
+ public Parser getParser(ParserOptions parserOptions) {
+ return new AS3Parser(parserOptions);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/pmd-flex/src/main/java/org/apache/flex/pmd/rule/FlexRuleChainVisitor.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/pmd-flex/src/main/java/org/apache/flex/pmd/rule/FlexRuleChainVisitor.java b/FlexPMD/language-module/pmd-flex/src/main/java/org/apache/flex/pmd/rule/FlexRuleChainVisitor.java
new file mode 100644
index 0000000..b42a49a
--- /dev/null
+++ b/FlexPMD/language-module/pmd-flex/src/main/java/org/apache/flex/pmd/rule/FlexRuleChainVisitor.java
@@ -0,0 +1,25 @@
+package org.apache.flex.pmd.rule;
+
+import net.sourceforge.pmd.Rule;
+import net.sourceforge.pmd.RuleContext;
+import net.sourceforge.pmd.lang.ast.Node;
+import net.sourceforge.pmd.lang.rule.AbstractRuleChainVisitor;
+
+import java.util.List;
+
+/**
+ * Created by christoferdutz on 06.03.15.
+ */
+public class FlexRuleChainVisitor extends AbstractRuleChainVisitor {
+
+ @Override
+ protected void visit(Rule rule, Node node, RuleContext ruleContext) {
+
+ }
+
+ @Override
+ protected void indexNodes(List<Node> list, RuleContext ruleContext) {
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/pmd-flex/src/main/java/org/apache/flex/pmd/rule/FlexRuleViolation.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/pmd-flex/src/main/java/org/apache/flex/pmd/rule/FlexRuleViolation.java b/FlexPMD/language-module/pmd-flex/src/main/java/org/apache/flex/pmd/rule/FlexRuleViolation.java
new file mode 100644
index 0000000..611677b
--- /dev/null
+++ b/FlexPMD/language-module/pmd-flex/src/main/java/org/apache/flex/pmd/rule/FlexRuleViolation.java
@@ -0,0 +1,23 @@
+package org.apache.flex.pmd.rule;
+
+import net.sourceforge.pmd.Rule;
+import net.sourceforge.pmd.RuleContext;
+import net.sourceforge.pmd.lang.rule.ParametricRuleViolation;
+import org.apache.flex.pmd.parser.ast.FlexNode;
+
+/**
+ * Created by christoferdutz on 06.03.15.
+ */
+public class FlexRuleViolation extends ParametricRuleViolation<FlexNode> {
+
+ public FlexRuleViolation(Rule rule, RuleContext ctx, FlexNode node, String message, int beginLine, int endLine) {
+ this(rule, ctx, node, message);
+
+ setLines(beginLine, endLine);
+ }
+
+ public FlexRuleViolation(Rule theRule, RuleContext ctx, FlexNode node, String message) {
+ super(theRule, ctx, node, message);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/pmd-flex/src/main/java/org/apache/flex/pmd/rule/FlexRuleViolationFactory.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/pmd-flex/src/main/java/org/apache/flex/pmd/rule/FlexRuleViolationFactory.java b/FlexPMD/language-module/pmd-flex/src/main/java/org/apache/flex/pmd/rule/FlexRuleViolationFactory.java
new file mode 100644
index 0000000..bfe70d0
--- /dev/null
+++ b/FlexPMD/language-module/pmd-flex/src/main/java/org/apache/flex/pmd/rule/FlexRuleViolationFactory.java
@@ -0,0 +1,28 @@
+package org.apache.flex.pmd.rule;
+
+import net.sourceforge.pmd.Rule;
+import net.sourceforge.pmd.RuleContext;
+import net.sourceforge.pmd.RuleViolation;
+import net.sourceforge.pmd.lang.ast.Node;
+import net.sourceforge.pmd.lang.rule.AbstractRuleViolationFactory;
+import net.sourceforge.pmd.lang.rule.RuleViolationFactory;
+import org.apache.flex.pmd.parser.ast.FlexNode;
+
+/**
+ * Created by christoferdutz on 06.03.15.
+ */
+public class FlexRuleViolationFactory extends AbstractRuleViolationFactory {
+
+ public static final RuleViolationFactory INSTANCE = new FlexRuleViolationFactory();
+
+ @Override
+ protected RuleViolation createRuleViolation(Rule rule, RuleContext ruleContext, Node node, String message) {
+ return new FlexRuleViolation(rule, ruleContext, (FlexNode) node, message);
+ }
+
+ @Override
+ protected RuleViolation createRuleViolation(Rule rule, RuleContext ruleContext, Node node, String message, int beginLine, int endLine) {
+ return new FlexRuleViolation(rule, ruleContext, (FlexNode) node, message, beginLine, endLine);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/pmd-flex/src/test/java/org/apache/flex/pmd/rule/BasicTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/pmd-flex/src/test/java/org/apache/flex/pmd/rule/BasicTest.java b/FlexPMD/language-module/pmd-flex/src/test/java/org/apache/flex/pmd/rule/BasicTest.java
new file mode 100644
index 0000000..8d21143
--- /dev/null
+++ b/FlexPMD/language-module/pmd-flex/src/test/java/org/apache/flex/pmd/rule/BasicTest.java
@@ -0,0 +1,16 @@
+package org.apache.flex.pmd.rule;
+
+import net.sourceforge.pmd.testframework.SimpleAggregatorTst;
+
+/**
+ * Created by christoferdutz on 06.03.15.
+ */
+public class BasicTest extends SimpleAggregatorTst {
+
+ private static final String RULESET = "flex-basic";
+
+ @Override
+ protected void setUp() {
+// addRule(RULESET, "simpletest");
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/pmd-flex/src/test/resources/org/apache/flex/pmd/rule/xml/simpletest.xml
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/pmd-flex/src/test/resources/org/apache/flex/pmd/rule/xml/simpletest.xml b/FlexPMD/language-module/pmd-flex/src/test/resources/org/apache/flex/pmd/rule/xml/simpletest.xml
new file mode 100644
index 0000000..2cf2f0b
--- /dev/null
+++ b/FlexPMD/language-module/pmd-flex/src/test/resources/org/apache/flex/pmd/rule/xml/simpletest.xml
@@ -0,0 +1,186 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<test-data>
+ <code-fragment id="basic-violation">
+ <![CDATA[
+public class Foo {
+ public void example() {
+ int x = 0;
+ int a = 0;
+ int b = 0;
+ int c = 0;
+ int d = 0;
+ int a1 = 0;
+ int a2 = 0;
+ int b1 = 0;
+ int b2 = 0;
+ int z = 0;
+ int h = 0;
+ int e = 0;
+ int f = 0;
+
+ if (a == b) {
+ if (a1 == b1) {
+ x = 2;
+ } else if (a2 == b2) {
+ x = 2;
+ } else {
+ x = 2;
+ }
+ } else if (c == d) {
+ while (c == d) {
+ x = 2;
+ }
+ } else if (e == f) {
+ for (int n = 0; n < h; n++) {
+ x = 2;
+ }
+ } else {
+ switch (z) {
+ case 1:
+ x = 2;
+ break;
+
+ case 2:
+ x = 2;
+ break;
+
+ case 3:
+ x = 2;
+ break;
+
+ default:
+ x = 2;
+ break;
+ }
+ }
+ }
+}
+ ]]>
+ </code-fragment>
+
+ <test-code>
+ <description>Simple method</description>
+ <rule-property name="reportLevel">1</rule-property>
+ <expected-problems>2</expected-problems>
+ <expected-messages>
+ <message>The class 'Foo' has a Cyclomatic Complexity of 2 (Highest = 1).</message>
+ <message>The method 'foo' has a Cyclomatic Complexity of 1.</message>
+ </expected-messages>
+ <code><![CDATA[
+public class Foo {
+ public void foo() {}
+}
+ ]]></code>
+ </test-code>
+ <test-code>
+ <description>testLessComplicatedThanReportLevel</description>
+ <rule-property name="reportLevel">10</rule-property>
+ <expected-problems>0</expected-problems>
+ <code><![CDATA[
+public class Foo {
+ public void foo() {}
+}
+ ]]></code>
+ </test-code>
+ <test-code>
+ <description>Complicated method</description>
+ <rule-property name="reportLevel">10</rule-property>
+ <expected-problems>2</expected-problems>
+ <expected-messages>
+ <message>The class 'Foo' has a Cyclomatic Complexity of 12 (Highest = 11).</message>
+ <message>The method 'example' has a Cyclomatic Complexity of 11.</message>
+ </expected-messages>
+ <code-ref id="basic-violation"/>
+ </test-code>
+ <test-code>
+ <description>Constructor</description>
+ <rule-property name="reportLevel">1</rule-property>
+ <expected-problems>2</expected-problems>
+ <expected-messages>
+ <message>The class 'Foo' has a Cyclomatic Complexity of 2 (Highest = 1).</message>
+ <message>The constructor 'Foo' has a Cyclomatic Complexity of 1.</message>
+ </expected-messages>
+ <code><![CDATA[
+public class Foo {
+ public Foo() {}
+}
+ ]]></code>
+ </test-code>
+ <test-code>
+ <description>
+ <![CDATA[
+Testing new parameter showClassMethods
+ ]]>
+ </description>
+ <rule-property name="showClassesComplexity">false</rule-property>
+ <expected-problems>1</expected-problems>
+ <code-ref id="basic-violation"/>
+ </test-code>
+ <test-code>
+ <description>
+ <![CDATA[
+Testing new parameter showMethodsMethods
+ ]]>
+ </description>
+ <rule-property name="showMethodsComplexity">false</rule-property>
+ <expected-problems>1</expected-problems>
+ <code-ref id="basic-violation"/>
+ </test-code>
+ <test-code>
+ <description>
+ <![CDATA[
+Testing default value of showClassMethods and showClassesComplexity
+ ]]>
+ </description>
+ <expected-problems>2</expected-problems>
+ <code-ref id="basic-violation"/>
+ </test-code>
+ <code-fragment id="constructor-violation"><![CDATA[
+public class Test {
+ public Test() {
+ if (a == 1) {
+ if (b == 2) {
+ System.out.println("b");
+ } else if (b == 1) {
+ }
+ } else {
+ }
+ }
+}
+ ]]></code-fragment>
+ <test-code>
+ <description>#984 Cyclomatic complexity should treat constructors like methods: 1 - showMethodsComplexity=true</description>
+ <rule-property name="showClassesComplexity">false</rule-property>
+ <rule-property name="showMethodsComplexity">true</rule-property>
+ <rule-property name="reportLevel">1</rule-property>
+ <expected-problems>1</expected-problems>
+ <code-ref id="constructor-violation"/>
+ </test-code>
+ <test-code>
+ <description>#984 Cyclomatic complexity should treat constructors like methods: 2 - showMethodsComplexity=false</description>
+ <rule-property name="showClassesComplexity">false</rule-property>
+ <rule-property name="showMethodsComplexity">false</rule-property>
+ <rule-property name="reportLevel">1</rule-property>
+ <expected-problems>0</expected-problems>
+ <code-ref id="constructor-violation"/>
+ </test-code>
+ <test-code reinitializeRule="true">
+ <description>#985 Suppressed methods shouldn't affect avg CyclomaticComplexity</description>
+ <rule-property name="reportLevel">2</rule-property>
+ <expected-problems>0</expected-problems>
+ <code><![CDATA[
+public class Test {
+ @SuppressWarnings("PMD.CyclomaticComplexity")
+ public Test() {
+ if (a == 1) {
+ if (b == 2) {
+ System.out.println("b");
+ } else if (b == 1) {
+ }
+ } else {
+ }
+ }
+}
+ ]]></code>
+ </test-code>
+</test-data>
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/pom.xml
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/pom.xml b/FlexPMD/language-module/pom.xml
new file mode 100755
index 0000000..6036389
--- /dev/null
+++ b/FlexPMD/language-module/pom.xml
@@ -0,0 +1,132 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache</groupId>
+ <artifactId>apache</artifactId>
+ <version>16</version>
+ </parent>
+
+ <groupId>org.apache.flex.pmd</groupId>
+ <artifactId>apache-flex-pmd</artifactId>
+ <version>2.0.0-SNAPSHOT</version>
+ <packaging>pom</packaging>
+
+ <name>Apache Flex: PMD Language-Module</name>
+
+ <mailingLists>
+ <mailingList>
+ <name>Apache Flex Dev List</name>
+ <subscribe>dev-subscribe@flex.apache.org</subscribe>
+ <unsubscribe>dev-unsubscribe@flex.apache.org</unsubscribe>
+ <post>dev@flex.apache.org</post>
+ <archive>http://mail-archives.apache.org/mod_mbox/flex-dev/</archive>
+ </mailingList>
+ <mailingList>
+ <name>Apache Flex User List</name>
+ <subscribe>users-subscribe@flex.apache.org</subscribe>
+ <unsubscribe>users-unsubscribe@flex.apache.org</unsubscribe>
+ <post>users@flex.apache.org</post>
+ <archive>http://mail-archives.apache.org/mod_mbox/flex-users/</archive>
+ </mailingList>
+ </mailingLists>
+
+ <scm>
+ <connection>scm:svn:https://git-wip-us.apache.org/repos/asf/flex-utilities.git</connection>
+ <developerConnection>scm:svn:https://git-wip-us.apache.org/repos/asf/flex-utilities.git</developerConnection>
+ <url>https://git-wip-us.apache.org/repos/asf/flex-utilities.git</url>
+ </scm>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <java.version>1.6</java.version>
+ <pmd.version>5.2.3</pmd.version>
+ <commons-lang.version>3.3.2</commons-lang.version>
+ </properties>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.2</version>
+ <configuration>
+ <source>${java.version}</source>
+ <target>${java.version}</target>
+ <encoding>${project.build.sourceEncoding}</encoding>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-resources-plugin</artifactId>
+ <version>2.7</version>
+ <configuration>
+ <encoding>${project.build.sourceEncoding}</encoding>
+ </configuration>
+ </plugin>
+
+ </plugins>
+ </build>
+
+ <modules>
+ <module>pmd-flex</module>
+ <module>parser</module>
+ <module>ruleset</module>
+ <module>utils</module>
+ </modules>
+
+
+ <!-- When building on the apache ci server, we want to get some source-release archives -->
+ <profiles>
+ <profile>
+ <id>flex-ci-build</id>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <version>2.5.1</version>
+ <executions>
+ <execution>
+ <id>assemble-sources-releases</id>
+ <phase>package</phase>
+ <goals>
+ <goal>single</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <descriptors>
+ <descriptor>src/assembly/assemble-zip.xml</descriptor>
+ <descriptor>src/assembly/assemble-gz.xml</descriptor>
+ </descriptors>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+
+</project>
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/pom.xml
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/pom.xml b/FlexPMD/language-module/ruleset/pom.xml
new file mode 100755
index 0000000..c5f68f4
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/pom.xml
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.flex.pmd</groupId>
+ <artifactId>apache-flex-pmd</artifactId>
+ <version>2.0.0-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.apache.flex.pmd.ruleset</groupId>
+ <artifactId>ruleset</artifactId>
+ <version>2.0.0-SNAPSHOT</version>
+ <packaging>pom</packaging>
+
+ <modules>
+ <module>ruleset-api</module>
+ <module>ruleset-flex-basic</module>
+ </modules>
+
+</project>
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/pom.xml
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/pom.xml b/FlexPMD/language-module/ruleset/ruleset-api/pom.xml
new file mode 100644
index 0000000..1e74a8c
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/pom.xml
@@ -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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.flex.pmd.ruleset</groupId>
+ <artifactId>ruleset</artifactId>
+ <version>2.0.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>ruleset-api</artifactId>
+ <version>2.0.0-SNAPSHOT</version>
+ <packaging>jar</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>net.sourceforge.pmd</groupId>
+ <artifactId>pmd-core</artifactId>
+ <version>${pmd.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ <version>${commons-lang.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.flex.pmd.parser</groupId>
+ <artifactId>parser-api</artifactId>
+ <version>2.0.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.flex.pmd</groupId>
+ <artifactId>utils</artifactId>
+ <version>2.0.0-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+
+</project>
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/files/IAs3File.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/files/IAs3File.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/files/IAs3File.java
new file mode 100644
index 0000000..7c6e54e
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/files/IAs3File.java
@@ -0,0 +1,23 @@
+/*
+ * 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 org.apache.flex.pmd.files;
+
+/**
+ * @author xagnetti
+ */
+public interface IAs3File extends IFlexFile {
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/files/IFlexFile.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/files/IFlexFile.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/files/IFlexFile.java
new file mode 100644
index 0000000..c905127
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/files/IFlexFile.java
@@ -0,0 +1,93 @@
+/*
+ * 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 org.apache.flex.pmd.files;
+
+import java.util.Set;
+
+/**
+ * @author xagnetti
+ */
+public interface IFlexFile {
+ /**
+ * @param stringToLookup
+ * @param linesToBeIgnored
+ * @return
+ */
+ boolean contains(final String stringToLookup,
+ final Set<Integer> linesToBeIgnored);
+
+ /**
+ * @return
+ */
+ String getClassName();
+
+ /**
+ * @return the token for comment closing
+ */
+ String getCommentClosingTag();
+
+ /**
+ * @return the token for comment opening
+ */
+ String getCommentOpeningTag();
+
+ /**
+ * @return java.io.File name
+ */
+ String getFilename();
+
+ /**
+ * @return java.io.File absolute path
+ */
+ String getFilePath();
+
+ /**
+ * @return
+ */
+ String getFullyQualifiedName();
+
+ /**
+ * @param lineIndex
+ * @return
+ */
+ String getLineAt(int lineIndex);
+
+ /**
+ * @return
+ */
+ int getLinesNb();
+
+ /**
+ * @return
+ */
+ String getPackageName();
+
+ /**
+ * @return the token for one line comment
+ */
+ String getSingleLineComment();
+
+ /**
+ * @return true if the file is a main MXML file
+ */
+ boolean isMainApplication();
+
+ /**
+ * @return true if the file is a MXML file
+ */
+ boolean isMxml();
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/files/IMxmlFile.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/files/IMxmlFile.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/files/IMxmlFile.java
new file mode 100644
index 0000000..01c6b75
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/files/IMxmlFile.java
@@ -0,0 +1,42 @@
+/*
+ * 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 org.apache.flex.pmd.files;
+
+/**
+ * @author xagnetti
+ */
+public interface IMxmlFile extends IFlexFile {
+ /**
+ * @return
+ */
+ String[] getActualScriptBlock();
+
+ /**
+ * @return
+ */
+ int getBeginningScriptBlock();
+
+ /**
+ * @return
+ */
+ int getEndingScriptBlock();
+
+ /**
+ * @return
+ */
+ String[] getScriptBlock();
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/files/impl/AbstractFlexFile.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/files/impl/AbstractFlexFile.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/files/impl/AbstractFlexFile.java
new file mode 100644
index 0000000..520494f
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/files/impl/AbstractFlexFile.java
@@ -0,0 +1,235 @@
+/*
+ * 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 org.apache.flex.pmd.files.impl;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.flex.pmd.files.IFlexFile;
+import org.apache.flex.pmd.utils.StackTraceUtils;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import java.util.logging.Logger;
+
+/**
+ * Abstract class representing a Flex File (either MXML or AS)
+ *
+ * @author xagnetti
+ */
+abstract class AbstractFlexFile implements IFlexFile {
+ private static final Logger LOGGER = Logger.getLogger(AbstractFlexFile.class.getName());
+
+ /**
+ * @param filePath
+ * @param rootPath
+ * @param className
+ * @param fileSeparator
+ * @return
+ */
+ protected static String computePackageName(final String filePath,
+ final CharSequence rootPath,
+ final String className,
+ final String fileSeparator) {
+ String temporaryPackage;
+
+ temporaryPackage = filePath.replace(className,
+ "").replace(rootPath,
+ "").replace(fileSeparator,
+ ".");
+ if (temporaryPackage.endsWith(".")) {
+ temporaryPackage = temporaryPackage.substring(0,
+ temporaryPackage.length() - 1);
+ }
+ if (temporaryPackage.length() > 0
+ && temporaryPackage.charAt(0) == '.') {
+ temporaryPackage = temporaryPackage.substring(1,
+ temporaryPackage.length());
+ }
+ return temporaryPackage;
+ }
+
+ private static boolean doesCurrentLineContain(final String line,
+ final String search) {
+ return line.contains(search);
+ }
+
+ private final String className;
+ private final File file;
+ private final List<String> lines;
+ private final String packageName;
+
+ /**
+ * @param underlyingFile
+ * @param rootDirectory
+ */
+ protected AbstractFlexFile(final File underlyingFile,
+ final File rootDirectory) {
+ final String filePath = underlyingFile.getPath();
+ final CharSequence rootPath = rootDirectory == null ? ""
+ : rootDirectory.getPath();
+
+ file = underlyingFile;
+ className = underlyingFile.getName();
+ packageName = computePackageName(filePath,
+ rootPath,
+ className,
+ System.getProperty("file.separator"));
+ lines = new ArrayList<String>();
+ try {
+ String[] linesArray;
+ linesArray = FileUtils.readLines(underlyingFile);
+ for (final String string : linesArray) {
+ lines.add(string);
+ }
+ } catch (final IOException e) {
+ LOGGER.warning(StackTraceUtils.print(e));
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.files.IFlexFile#contains(java.lang.String, int)
+ */
+ public final boolean contains(final String stringToLookup,
+ final Set<Integer> linesToBeIgnored) {
+ int lineIndex = 1;
+ boolean found = false;
+
+ for (final String line : lines) {
+ if (doesCurrentLineContain(line,
+ stringToLookup)
+ && !linesToBeIgnored.contains(lineIndex)) {
+ found = true;
+ break;
+ }
+ lineIndex++;
+ }
+ return found;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public final boolean equals(final Object obj) {
+ return obj != null
+ && obj instanceof AbstractFlexFile && hashCode() == ((AbstractFlexFile) obj).hashCode();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.files.IFlexFile#getClassName()
+ */
+ public final String getClassName() {
+ return className;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.files.IFlexFile#getCommentClosingTag()
+ */
+ public abstract String getCommentClosingTag();
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.files.IFlexFile#getCommentOpeningTag()
+ */
+ public abstract String getCommentOpeningTag();
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.files.IFlexFile#getFilename()
+ */
+ public final String getFilename() {
+ return file.getName();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.files.IFlexFile#getFilePath()
+ */
+ public final String getFilePath() {
+ return file.toURI().getPath();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.files.IFlexFile#getFullyQualifiedName()
+ */
+ public final String getFullyQualifiedName() {
+ return (StringUtils.isEmpty(packageName) ? ""
+ : packageName
+ + ".")
+ + className;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.files.IFlexFile#getLineAt(int)
+ */
+ public String getLineAt(final int lineIndex) {
+ return lines.get(lineIndex - 1);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.files.IFlexFile#getLines()
+ */
+ public final List<String> getLines() {
+ return lines;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.files.IFlexFile#getLinesNb()
+ */
+ public int getLinesNb() {
+ return lines.size();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.files.IFlexFile#getPackageName()
+ */
+ public final String getPackageName() {
+ return packageName;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ return getFilePath().hashCode();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.files.IFlexFile#isMainApplication()
+ */
+ public abstract boolean isMainApplication();
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.files.IFlexFile#isMxml()
+ */
+ public abstract boolean isMxml();
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/files/impl/As3File.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/files/impl/As3File.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/files/impl/As3File.java
new file mode 100644
index 0000000..0285558
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/files/impl/As3File.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 org.apache.flex.pmd.files.impl;
+
+import org.apache.flex.pmd.files.IAs3File;
+
+import java.io.File;
+
+/**
+ * @author xagnetti
+ */
+class As3File extends AbstractFlexFile implements IAs3File {
+ /**
+ * @param file
+ * @param rootDirectory
+ */
+ protected As3File(final File file,
+ final File rootDirectory) {
+ super(file, rootDirectory);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.files.impl.AbstractFlexFile#getCommentClosingTag()
+ */
+ @Override
+ public final String getCommentClosingTag() {
+ return "*/";
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.files.impl.AbstractFlexFile#getCommentOpeningTag()
+ */
+ @Override
+ public final String getCommentOpeningTag() {
+ return "/*";
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.files.IFlexFile#getSingleLineComment()
+ */
+ public String getSingleLineComment() {
+ return "//";
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.files.impl.AbstractFlexFile#isMainApplication()
+ */
+ @Override
+ public final boolean isMainApplication() {
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.files.impl.AbstractFlexFile#isMxml()
+ */
+ @Override
+ public final boolean isMxml() {
+ return false;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/files/impl/FileUtils.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/files/impl/FileUtils.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/files/impl/FileUtils.java
new file mode 100644
index 0000000..82cc5ed
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/files/impl/FileUtils.java
@@ -0,0 +1,268 @@
+/*
+ * 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 org.apache.flex.pmd.files.impl;
+
+import net.sourceforge.pmd.PMDException;
+import org.apache.flex.pmd.files.IFlexFile;
+import org.apache.flex.pmd.utils.FlexFilter;
+import org.apache.flex.pmd.utils.StackTraceUtils;
+
+import java.io.*;
+import java.util.*;
+import java.util.logging.Logger;
+
+/**
+ * @author xagnetti
+ */
+public final class FileUtils {
+ /**
+ * @param source
+ * @param sourceList
+ * @param packageToExclude
+ * @param excludePatterns
+ * @return
+ * @throws net.sourceforge.pmd.PMDException
+ */
+ public static Map<String, IFlexFile> computeFilesList(final File source,
+ final List<File> sourceList,
+ final String packageToExclude,
+ final List<String> excludePatterns) throws PMDException {
+ final Map<String, IFlexFile> files = new LinkedHashMap<String, IFlexFile>();
+ final FlexFilter flexFilter = new FlexFilter();
+ final Collection<File> foundFiles = getFlexFiles(source, sourceList, flexFilter);
+
+ for (final File sourceFile : foundFiles) {
+ final AbstractFlexFile file = create(sourceFile,
+ source);
+
+ if (("".equals(packageToExclude) || !file.getFullyQualifiedName().startsWith(packageToExclude))
+ && !currentPackageIncludedInExcludePatterns(file.getFullyQualifiedName(),
+ excludePatterns)) {
+ files.put(file.getFullyQualifiedName(),
+ file);
+ }
+ }
+
+ return files;
+ }
+
+ /**
+ * @param sourceFile
+ * @param sourceDirectory
+ * @return
+ */
+ public static AbstractFlexFile create(final File sourceFile,
+ final File sourceDirectory) {
+ AbstractFlexFile file;
+
+ if (sourceFile.getName().endsWith(".as")) {
+ file = new As3File(sourceFile, sourceDirectory);
+ } else {
+ file = new MxmlFile(sourceFile, sourceDirectory);
+ }
+
+ return file;
+ }
+
+ private static boolean currentPackageIncludedInExcludePatterns(final String fullyQualifiedName,
+ final List<String> excludePatterns) {
+ if (excludePatterns != null) {
+ for (final String excludePattern : excludePatterns) {
+ if (fullyQualifiedName.startsWith(excludePattern)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ /**
+ * @param file
+ * @return
+ * @throws IOException
+ */
+ public static String[] readLines(final File file) throws IOException {
+ final List<String> lines = readFile(file);
+
+ return lines.toArray(new String[lines.size()]);
+ }
+
+
+ private static Collection<File> getFlexFiles(final File source,
+ final List<File> sourceList,
+ final FlexFilter flexFilter) throws PMDException {
+ if (source == null
+ && sourceList == null) {
+ throw new PMDException("sourceDirectory is not specified", null);
+ }
+ Collection<File> foundFiles;
+ if (source == null) {
+ foundFiles = listFiles(sourceList,
+ flexFilter,
+ true);
+ } else {
+ if (source.isDirectory()) {
+ foundFiles = listFiles(source,
+ flexFilter,
+ true);
+ } else {
+ foundFiles = new ArrayList<File>();
+ foundFiles.add(source);
+ }
+ }
+ if (foundFiles.isEmpty()) {
+ return new ArrayList<File>();
+ }
+ return foundFiles;
+ }
+
+ public static class FilePathComparator implements Comparator<File> {
+ public int compare(final File arg0,
+ final File arg1) {
+ return arg0.getAbsolutePath().compareTo(arg1.getAbsolutePath());
+ }
+ }
+
+ public static final Logger LOGGER = Logger.getLogger(FileUtils.class.getName());
+
+ /**
+ * @param line
+ * @return
+ */
+ public static boolean isLineACorrectStatement(final String line) {
+ return line.compareTo("") != 0
+ && lrtrim(line).compareTo("{") != 0 && lrtrim(line).compareTo("}") != 0
+ && line.endsWith(";");
+ }
+
+ /**
+ * @param directory
+ * @param filter
+ * @param recurse
+ * @return
+ */
+ public static Collection<File> listFiles(final File directory,
+ final FilenameFilter filter,
+ final boolean recurse) {
+ final ArrayList<File> files = listFilesRecurse(directory,
+ filter,
+ recurse);
+ Collections.sort(files,
+ new FilePathComparator());
+ return files;
+ }
+
+ /**
+ * @param sourceDirectory
+ * @param filter
+ * @param recurse
+ * @return
+ */
+ public static Collection<File> listFiles(final List<File> sourceDirectory,
+ final FilenameFilter filter,
+ final boolean recurse) {
+ final ArrayList<File> files = new ArrayList<File>();
+
+ for (final File topDirectory : sourceDirectory) {
+ files.addAll(listFilesRecurse(topDirectory,
+ filter,
+ recurse));
+ }
+
+ Collections.sort(files,
+ new FilePathComparator());
+ return files;
+ }
+
+ /**
+ * @param file
+ * @return
+ */
+ public static List<String> readFile(final File file) {
+ final List<String> result = new ArrayList<String>();
+
+ BufferedReader inReader = null;
+ try {
+ final Reader reader = new InputStreamReader(new FileInputStream(file), "UTF-8");
+ inReader = new BufferedReader(reader);
+
+ String line = readLine(inReader);
+
+ while (line != null) {
+ result.add(line);
+ line = readLine(inReader);
+ }
+ inReader.close();
+ } catch (final IOException e) {
+ StackTraceUtils.print(e);
+ }
+ return result;
+ }
+
+ private static ArrayList<File> listFilesRecurse(final File directory,
+ final FilenameFilter filter,
+ final boolean recurse) {
+ final ArrayList<File> files = new ArrayList<File>();
+ final File[] entries = directory.listFiles();
+
+ if (entries != null) {
+ for (final File entry : entries) {
+ if (filter == null
+ || filter.accept(directory,
+ entry.getName())) {
+ files.add(entry);
+ }
+ if (recurse
+ && entry.isDirectory()) {
+ files.addAll(listFilesRecurse(entry,
+ filter,
+ recurse));
+ }
+ }
+ }
+ return files;
+ }
+
+ private static String lrtrim(final String source) {
+ return ltrim(rtrim(source));
+ }
+
+ /* remove leading whitespace */
+ private static String ltrim(final String source) {
+ return source.replaceAll("^\\s+",
+ "");
+ }
+
+ private static String readLine(final BufferedReader inReader) throws IOException {
+ final String line = inReader.readLine();
+
+ if (line != null) {
+ return line.replaceAll("\uFEFF",
+ "");
+ }
+ return null;
+ }
+
+ /* remove trailing whitespace */
+ private static String rtrim(final String source) {
+ return source.replaceAll("\\s+$",
+ "");
+ }
+
+ private FileUtils() {
+ }
+}
[11/24] git commit: [flex-utilities]
[refs/heads/feature/pmd-5.2-language-module] - Initial commit of the PMD
language module for Apache Flex
Posted by cd...@apache.org.
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/switches/TooFewBrancheInSwitchStatementRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/switches/TooFewBrancheInSwitchStatementRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/switches/TooFewBrancheInSwitchStatementRule.java
new file mode 100644
index 0000000..b941a69
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/switches/TooFewBrancheInSwitchStatementRule.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 org.apache.flex.pmd.rules.switches;
+
+import net.sourceforge.pmd.PropertyDescriptor;
+import org.apache.flex.pmd.parser.IParserNode;
+import org.apache.flex.pmd.rules.core.AbstractAstFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+import org.apache.flex.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 getProperty((PropertyDescriptor<Integer>) getPropertyDescriptor(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
+ * 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/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/unused/AbstractUnusedVariableRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/unused/AbstractUnusedVariableRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/unused/AbstractUnusedVariableRule.java
new file mode 100644
index 0000000..6c4d05f
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/unused/AbstractUnusedVariableRule.java
@@ -0,0 +1,112 @@
+/*
+ * 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 org.apache.flex.pmd.rules.unused;
+
+import org.apache.flex.pmd.parser.IParserNode;
+import org.apache.flex.pmd.parser.NodeKind;
+import org.apache.flex.pmd.rules.core.AbstractAstFlexRule;
+
+import java.util.Map;
+
+/**
+ * @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/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/unused/EmptyPrivateMethodRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/unused/EmptyPrivateMethodRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/unused/EmptyPrivateMethodRule.java
new file mode 100644
index 0000000..a204cc8
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/unused/EmptyPrivateMethodRule.java
@@ -0,0 +1,37 @@
+/*
+ * 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 org.apache.flex.pmd.rules.unused;
+
+import org.apache.flex.pmd.nodes.IFunction;
+import org.apache.flex.pmd.nodes.Modifier;
+import org.apache.flex.pmd.rules.core.AbstractAstFlexRule;
+import org.apache.flex.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/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/unused/UnusedFieldRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/unused/UnusedFieldRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/unused/UnusedFieldRule.java
new file mode 100644
index 0000000..08d6e97
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/unused/UnusedFieldRule.java
@@ -0,0 +1,116 @@
+/*
+ * 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 org.apache.flex.pmd.rules.unused;
+
+import org.apache.flex.pmd.parser.IParserNode;
+import org.apache.flex.pmd.parser.KeyWords;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+import java.util.LinkedHashMap;
+import java.util.List;
+
+/**
+ * @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/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/unused/UnusedLocalVariableRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/unused/UnusedLocalVariableRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/unused/UnusedLocalVariableRule.java
new file mode 100644
index 0000000..3ccd92d
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/unused/UnusedLocalVariableRule.java
@@ -0,0 +1,71 @@
+/*
+ * 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 org.apache.flex.pmd.rules.unused;
+
+import org.apache.flex.pmd.parser.IParserNode;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+import java.util.LinkedHashMap;
+
+/**
+ * @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/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/unused/UnusedParameterRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/unused/UnusedParameterRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/unused/UnusedParameterRule.java
new file mode 100644
index 0000000..42de2e1
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/unused/UnusedParameterRule.java
@@ -0,0 +1,202 @@
+/*
+ * 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 org.apache.flex.pmd.rules.unused;
+
+import org.apache.flex.pmd.parser.IParserNode;
+import org.apache.flex.pmd.parser.KeyWords;
+import org.apache.flex.pmd.parser.NodeKind;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+import org.apache.flex.pmd.rules.parsley.utils.MetaDataTag;
+import org.apache.flex.pmd.rules.parsley.utils.ParsleyMetaData;
+
+import java.util.LinkedHashMap;
+
+/**
+ * @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(MetaDataTag.Location.FUNCTION)
+ .containsKey(metaDataChild.getStringValue())) {
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/unused/UnusedPrivateMethodRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/unused/UnusedPrivateMethodRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/unused/UnusedPrivateMethodRule.java
new file mode 100644
index 0000000..e68c21a
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/unused/UnusedPrivateMethodRule.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 org.apache.flex.pmd.rules.unused;
+
+import org.apache.flex.pmd.files.IAs3File;
+import org.apache.flex.pmd.nodes.*;
+import org.apache.flex.pmd.parser.IParserNode;
+import org.apache.flex.pmd.rules.core.AbstractAstFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+import java.util.*;
+
+/**
+ * @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/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/architecture.xml
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/architecture.xml b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/architecture.xml
new file mode 100644
index 0000000..2b7776b
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/architecture.xml
@@ -0,0 +1,120 @@
+<?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.sourceforge.net/ruleset/2.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.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"
+ language="flex">
+ <description></description>
+ <priority>3</priority>
+ <example>
+package com.adobe.ac
+{
+ import mx.controls.ComboBox; // VIOLATION
+
+ public class MyModelClass
+ {
+ }
+}
+ </example>
+ </rule>
+
+ <rule class="org.apache.flex.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/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/asdocs.xml
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/asdocs.xml b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/asdocs.xml
new file mode 100644
index 0000000..fca2dee
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/asdocs.xml
@@ -0,0 +1,49 @@
+<?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.sourceforge.net/ruleset/2.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.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/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/basic_mxml.xml
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/basic_mxml.xml b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/basic_mxml.xml
new file mode 100644
index 0000000..1378fc7
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/basic_mxml.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="Basic MXML Rules"
+ xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.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/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/binding.xml
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/binding.xml b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/binding.xml
new file mode 100644
index 0000000..a2c2b43
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/binding.xml
@@ -0,0 +1,71 @@
+<?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.sourceforge.net/ruleset/2.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.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/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/cairngorm.xml
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/cairngorm.xml b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/cairngorm.xml
new file mode 100644
index 0000000..6083ba0
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/cairngorm.xml
@@ -0,0 +1,135 @@
+<?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.sourceforge.net/ruleset/2.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.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/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/component.xml
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/component.xml b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/component.xml
new file mode 100644
index 0000000..b851ac5
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/component.xml
@@ -0,0 +1,44 @@
+<?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.sourceforge.net/ruleset/2.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.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/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/css.xml
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/css.xml b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/css.xml
new file mode 100644
index 0000000..89d8597
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/css.xml
@@ -0,0 +1,42 @@
+<?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.sourceforge.net/ruleset/2.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.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/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/empty.xml
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/empty.xml b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/empty.xml
new file mode 100644
index 0000000..f747c0d
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/empty.xml
@@ -0,0 +1,67 @@
+<?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.sourceforge.net/ruleset/2.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.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>
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/event.xml
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/event.xml b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/event.xml
new file mode 100644
index 0000000..6213052
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/event.xml
@@ -0,0 +1,148 @@
+<?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="Event Rules"
+ xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd"
+ xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
+
+ <description>
+ The Event ruleset contains a collection of rules related to event bad practices.
+ </description>
+
+ <rule class="com.adobe.ac.pmd.rules.event.EventMissingCloneFunctionRule"
+ message="The clone event must be overiden in a custom event">
+ <description>When creating your own custom Event class, you must override the inherited Event.clone() method in order for it to duplicate the properties of your custom class. If you do not set all the properties that you add in your event subclass, those properties will not have the correct values when the event is cloned. This is important because the Flex SDK clones events whenever redispatching takes place. </description>
+ <priority>1</priority>
+ <example>
+public class FirstCustomEvent // VIOLATION - clone method is missing
+{
+ public var lala : String;
+
+ public function FirstCustomEvent()
+ {
+ }
+}
+ </example>
+ </rule>
+
+ <rule
+ class="com.adobe.ac.pmd.rules.event.PublicVariableInCustomEventRule"
+ message="No public variables should be inside a custom event. This variable ({0}) is public">
+ <description>In order to improve encapsulation in your custom event, it is better not to have public variable in your event. Prefer having read-only attributes, set by the event constructor.</description>
+ <priority>3</priority>
+ <example>
+public class FirstCustomEvent
+{
+ public var lala : String; // VIOLATION
+
+ public function FirstCustomEvent()
+ {
+ }
+}
+ </example>
+ </rule>
+
+ <rule
+ class="com.adobe.ac.pmd.rules.event.ConstructorDispatchingEventRule"
+ message="An event is dispatched in a constructor">
+ <description>This is pointless, since event listeners cannot be attached to an object before it has been constructed, so nothing can ever hear the event</description>
+ <priority>1</priority>
+ <example>
+public class BigModel
+{
+ public function BigModel()
+ {
+ dispatchEvent( new Event( "pointlessEvent" ) );
+ }
+}
+ </example>
+ </rule>
+ <rule class="com.adobe.ac.pmd.rules.event.DefaultEventNameRule"
+ message="Event name should be set explicitly">
+ <priority>3</priority>
+ <example>
+public class DefaultNameEvent extends Event
+{
+ public function DefaultNameEvent( type : String = "" )
+ {
+ super( type );
+ }
+}
+ </example>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.event.DispatchHardCodedEventNameRule"
+ message="DispatchEvent function must dispatch constant strings">
+ <description>You should not dispatch a plain string. If you rename this string, you need to replace the string listener as well. Use constants instead</description>
+ <priority>1</priority>
+ <example>
+public class Foo
+{
+ public function bar() : void
+ {
+ dispatch( new Event( "myHardCodedEvent" ) ); // VIOLATION
+ }
+}
+ </example>
+ </rule>
+
+ <rule
+ class="com.adobe.ac.pmd.rules.event.ListenForHardCodedEventNameRule"
+ message="addEventListener must not contain hard coded strings">
+ <description>You should not listen for a plain string. If you rename this string, you need to replace the string listener as well. Use constants instead</description>
+ <priority>1</priority>
+ <example>
+public class Foo
+{
+ public function bar() : void
+ {
+ addEventListener( "myHardCodedEvent", handleMyHardCodedEvent ); // VIOLATION
+ }
+}
+ </example>
+ </rule>
+
+ <rule
+ class="com.adobe.ac.pmd.rules.event.UnboundTypeInMetadataRule"
+ message="This type ({0}) was not found within the scope against which PMD was run">
+ <priority>1</priority>
+ <example>
+[Event(name="myTypeEvent",type="UnknownType")] // VIOLATION
+public class UnboundMetadata
+{
+}
+ </example>
+ </rule>
+
+ <rule
+ class="com.adobe.ac.pmd.rules.event.UntypedEventMetadataRule"
+ message="This event type is not specified">
+ <description>Specifying a type will allow Flash builder and the class to have this event exposed in its API</description>
+ <priority>3</priority>
+ <example>
+[Event(name="myTypeEvent")] // VIOLATION
+public class UnTypedMetadata
+{
+}
+ </example>
+ </rule>
+
+</ruleset>
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/flexunit.xml
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/flexunit.xml b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/flexunit.xml
new file mode 100644
index 0000000..9649ceb
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/flexunit.xml
@@ -0,0 +1,35 @@
+<?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="FlexUnit Rules"
+ xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd"
+ xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
+
+ <description>
+ The FlexUnit Ruleset contains a collection of good practices related to FlexUnit (1 and 4).
+ </description>
+
+ <rule class="com.adobe.ac.pmd.rules.flexunit.EmptyUnitTest"
+ message="A test should contain at least one assertion">
+ <priority>3</priority>
+ </rule>
+
+</ruleset>
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/indentation.xml
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/indentation.xml b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/indentation.xml
new file mode 100644
index 0000000..0ca4684
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/indentation.xml
@@ -0,0 +1,32 @@
+<?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="Indentations Rules"
+ xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd"
+ xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
+
+ <description/>
+
+ <rule class="com.adobe.ac.pmd.rules.style.TabUsedAsIndentorRule" message="Tabulations are not accepted for indentation. Please use spaces instead.">
+ <priority>3</priority>
+ </rule>
+
+</ruleset>
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/maintanability.xml
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/maintanability.xml b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/maintanability.xml
new file mode 100644
index 0000000..6f7ca5c
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/maintanability.xml
@@ -0,0 +1,237 @@
+<?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="Maintanability Rules"
+ xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd"
+ xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
+
+ <description>
+ The Maintanability ruleset contains a collection of good practices around Maintanability.
+ </description>
+
+ <rule since="1.1" class="com.adobe.ac.pmd.rules.maintanability.OnlyOneReturnRule" message="A method should have only one exit point, and that should be the last statement in the method">
+ <priority>3</priority>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.maintanability.AlertShowRule" message="Do not call Alert.show directly">
+ <description>You should not Alert.show() directly. If an error occurred in the system, you should probably use an ErrorManager to have a consistent way to manage those errors.</description>
+ <priority>1</priority>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.maintanability.ExcessiveImportRule"
+ message="A high number of imports can indicate a high degree of coupling within an object. ({0} maximum but {1} actually)">
+ <description>A high number of imports can indicate a high degree of coupling within an object. Rule counts the number of unique imports and reports a violation if the count is above the user defined threshold.</description>
+ <priority>3</priority>
+ <properties>
+ <property name="maximum">
+ <value>15</value>
+ </property>
+ </properties>
+ <example>
+import blah.blah.Baz;
+import blah.blah.Bif;
+// 18 others from the same package elided
+public class Foo
+{
+ public function doWork() : void
+ {
+ }
+}
+ </example>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.maintanability.TrueFalseConditionRule"
+ message="This test contains a hard coded boolean value. You could remove it by having '{0}'">
+ <priority>3</priority>
+ <example>
+if ( true ) // VIOLATION
+{
+ if ( myCondition == false ) // VIOLATION
+ {
+ }
+}
+ </example>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.maintanability.AvoidUsingPublicStaticFieldRule"
+ message="If this field ({0}) was meant to be a constant, make it constant. Otherwise, if it is used as a global variable, you may want to redesign this class">
+ <priority>3</priority>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.maintanability.DynamicClassRule" message="A class must not be dynamic">
+ <description>When using dynamic classes, you cannot control how the developer will use your class. It makes refactoring really difficult</description>
+ <priority>1</priority>
+ <example>
+dynamic public class DynamicObject // VIOLATION
+{
+}
+ </example>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.maintanability.forbiddentypes.UseObjectTypeRule"
+ message="Do not use Object class">
+ <description>It is a bad practice to use the dynamic class Object. Prefer using strongly typed object, or marker interface in order to avoid silent compilation errors while refactoring</description>
+ <priority>1</priority>
+ <example>
+public class Foo
+{
+ public var bar : Object; // VIOLATION
+}
+ </example>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.maintanability.forbiddentypes.UseDictionaryTypeRule"
+ message="Do not use Dictionnary class">
+ <description>It is a bad practice to use the dynamic class Dictionary. Prefer using strongly typed object, or marker interface in order to avoid silent compilation errors while refactoring</description>
+ <priority>1</priority>
+ <example>
+public class Foo
+{
+ public var bar : Dictionnary; // VIOLATION
+}
+ </example>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.maintanability.NonStaticConstantFieldRule"
+ message="A constant field should be static ({0})">
+ <description>
+ </description>
+ <priority>1</priority>
+ <example>
+public class MyObject {
+ public static const MY_STATIC_CONSTANT : String = "myStaticConstant";
+ public const MY_NON_STATIC_CONSTANT : String = "myStaticConstant"; // VIOLATION
+}
+ </example>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.maintanability.forbiddentypes.UseGenericTypeRule"
+ message="Use strongly typed objects instead of *">
+ <description></description>
+ <priority>1</priority>
+ <example>
+public class Foo
+{
+ public var bar : *; // VIOLATION
+}
+ </example>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.maintanability.UselessOverridenFunctionRule"
+ message="This method is empty. This should be removed ({0})">
+ <description>This function is not needed.</description>
+ <priority>3</priority>
+ <example>
+override protected function createChildren() : void
+{
+ super.createChildren();
+}
+ </example>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.maintanability.AvoidProtectedFieldInFinalClassRule"
+ message="Protected accessors are useless in a final class. Make it private ({0})">
+ <priority>3</priority>
+ <example>
+final public class Foo
+{
+ protected var bar : int; // VIOLATION
+}
+ </example>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.maintanability.AvoidUsingWithKeyWordRule"
+ message="You should not use the with keyword. It does not help readability">
+ <priority>3</priority>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.maintanability.ArrayFieldWithNoArrayElementTypeRule"
+ message="ArrayElementType metadata is not specified for this array-type field ({0})">
+ <description>
+ </description>
+ <priority>3</priority>
+ <example>
+public class ArrayVO {
+ public var items:Array; //VIOLATION
+
+ [ArrayElementType("model.vo.MenuItemVO")]
+ public var menuItems : Array;
+}
+ </example>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.maintanability.ClassAndExtensionAreIdenticalRule"
+ message="The extension name is the same as the class name">
+ <description/>
+ <priority>3</priority>
+ <example>
+package com.MyCompany
+{
+ public class SomeClass extends mx.SomeClass // VIOLATION
+ {
+ }
+}
+ </example>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.maintanability.ProtectedStaticMethodRule"
+ message="This method ({0}) should be private">
+ <description/>
+ <priority>3</priority>
+ <example>
+protected static function foo() : void // VIOLATION
+{
+}
+ </example>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.maintanability.EmptyStatementRule"
+ message="This statement is empty">
+ <description/>
+ <priority>5</priority>
+ <example>
+protected function foo() : void
+{
+ var i : int = 0;
+
+ ; // VIOLATION
+}
+ </example>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.maintanability.ReferenceToVariableBindingFromItsInitializerRule"
+ message="The initializer refers to its variable. Its value will be null.">
+ <priority>1</priority>
+ <example>
+package
+{
+ public class Foo
+ {
+ public static const XYZ:String = XYZ; // meant to be "xyz"
+ }
+}
+ </example>
+ </rule>
+ <rule class="com.adobe.ac.pmd.rules.maintanability.AvoidUseOfAsKeywordRule"
+ message="Enforce that as is not used (silently ignores the cast and nulls the property when the type is wrong)">
+ <priority>5</priority>
+ </rule>
+</ruleset>
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/multitouch.xml
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/multitouch.xml b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/multitouch.xml
new file mode 100644
index 0000000..c1a82dd
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/multitouch.xml
@@ -0,0 +1,40 @@
+<?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="Multitouch screen Rules"
+ xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd"
+ xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
+
+ <description>
+ The MultiTouch ruleset contains a collection of good practices when developping multitouch applications.
+ </description>
+
+ <rule since="1.2" class="com.adobe.ac.pmd.rules.multiscreen.AvoidRollMouseEventRule"
+ message="Roll mouse events are not getting caught by a multi-touch device.">
+ <priority>1</priority>
+ </rule>
+
+ <rule since="1.2" class="com.adobe.ac.pmd.rules.multiscreen.AvoidTooltipRule"
+ message="Tooltip cannot be visible on a multi-touch device.">
+ <priority>1</priority>
+ </rule>
+
+</ruleset>
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/naming.xml
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/naming.xml b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/naming.xml
new file mode 100644
index 0000000..4a94511
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/naming.xml
@@ -0,0 +1,163 @@
+<?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="Naming Rules"
+ xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd"
+ xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
+
+ <description>
+ The Basic As3 Ruleset contains a collection of good practices which everyone should follow.
+ </description>
+
+ <rule class="com.adobe.ac.pmd.rules.naming.TooShortVariableRule"
+ message="This variable name is too short ({0} characters minimum, but {1} actually)">
+ <description>Detects when a field, local, or parameter has a very short name.</description>
+ <priority>5</priority>
+ <properties>
+ <property name="minimum">
+ <value>3</value>
+ </property>
+ </properties>
+ <example>
+public class Something
+{
+ private var q : int = 15; // VIOLATION - Field
+
+ public function foo( as : String ) : void // VIOLATION - Formal
+ {
+ var r : int = 20 + q; // VIOLATION - Local
+ }
+}
+ </example>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.naming.PackageCaseRule"
+ message="A package name should be lower case ({0})">
+ <description>Detects when a package definition contains upper case characters.</description>
+ <priority>3</priority>
+ <example>
+ <![CDATA[
+package com.MyCompany // VIOLATION <- should be lower case name
+{
+ public class SomeClass
+ {
+ }
+}
+ ]]>
+ </example>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.naming.VariableNameEndingWithNumericRule"
+ message="Using digits at the end of a symbol does not help understanging the meaning of it. ({0})">
+ <priority>3</priority>
+ <example>
+ <![CDATA[
+public class SomeClass
+{
+ public var correctField1 : int = 0; // VIOLATION <- numeric suffix is forbidden
+}
+ ]]>
+ </example>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.naming.PropertyHiddenByLocalVariableRule"
+ message="A class property is hidden by this local variable ({0})">
+ <priority>3</priority>
+ <example>
+public class SomeClass
+{
+ public var myField : int = 0;
+
+ public function foo() : void
+ {
+ var myField : int = 9; // VIOLATION
+ }
+}
+ </example>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.naming.IncorrectClassCase"
+ message="A class name must start by an uppercase character">
+ <description></description>
+ <priority>3</priority>
+ <example>
+public class foo // VIOLATION
+{
+}
+ </example>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.naming.WronglyNamedVariableRule"
+ message="This variable ({0}) seems to be incorrectly named. Let your creativity flow">
+ <priority>3</priority>
+ <example>
+ <![CDATA[
+public class SomeClass
+{
+ public var myField : int = 0; // VIOLATION <- my prefix is forbidden
+
+ public function tmpFoo() : void // VIOLATION <- tmp prefix is forbidden
+ {
+ var tempFoo : int = 9; // VIOLATION <- temp prefix is forbidden
+ }
+}
+ ]]>
+ </example>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.naming.BooleanAttributeShouldContainIsHasRule"
+ message="Differentiate the Boolean variables from other variable types ({0}); for example: canAnimate, isConnected, or hasChildren.">
+ <priority>5</priority>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.naming.CapitalizeConstantsRule"
+ message="Constant variables should be in all CAPS with each word separated by an underscore ({0})">
+ <priority>3</priority>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.naming.InterfaceNamingRule"
+ message="Interface name should start with I">
+ <priority>1</priority>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.naming.TooLongFunctionNameRule"
+ message="This function name ({0}) is too long ({1} characters minimum, but {2} actually)">
+ <priority>5</priority>
+ <properties>
+ <property name="minimum">
+ <value>3</value>
+ </property>
+ </properties>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.naming.IncorrectEventHandlerNameRule"
+ message="This event handler name ({0}) is not correct. You should use [{1}] as prefix and [{2}] as suffix">
+ <priority>5</priority>
+ <properties>
+ <property name="prefix">
+ <value>on</value>
+ </property>
+ <property name="suffix">
+ <value></value>
+ </property>
+ </properties>
+ </rule>
+</ruleset>
[13/24] git commit: [flex-utilities]
[refs/heads/feature/pmd-5.2-language-module] - Initial commit of the PMD
language module for Apache Flex
Posted by cd...@apache.org.
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/naming/TooShortVariableRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/naming/TooShortVariableRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/naming/TooShortVariableRule.java
new file mode 100644
index 0000000..b3c6f1f
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/naming/TooShortVariableRule.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 org.apache.flex.pmd.rules.naming;
+
+import net.sourceforge.pmd.PropertyDescriptor;
+import org.apache.flex.pmd.rules.core.AbstractRegexpBasedRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+import org.apache.flex.pmd.rules.core.thresholded.IThresholdedRule;
+
+import java.util.regex.Matcher;
+
+/**
+ * @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 getProperty((PropertyDescriptor<Integer>) getPropertyDescriptor(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;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/naming/VariableNameEndingWithNumericRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/naming/VariableNameEndingWithNumericRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/naming/VariableNameEndingWithNumericRule.java
new file mode 100644
index 0000000..60804b4
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/naming/VariableNameEndingWithNumericRule.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 org.apache.flex.pmd.rules.naming;
+
+import org.apache.flex.pmd.nodes.IClass;
+import org.apache.flex.pmd.nodes.IFunction;
+import org.apache.flex.pmd.nodes.INamableNode;
+import org.apache.flex.pmd.rules.core.AbstractAstFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+import java.util.List;
+
+/**
+ * @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/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/naming/WronglyNamedVariableRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/naming/WronglyNamedVariableRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/naming/WronglyNamedVariableRule.java
new file mode 100644
index 0000000..4a0c9ff
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/naming/WronglyNamedVariableRule.java
@@ -0,0 +1,109 @@
+/*
+ * 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 org.apache.flex.pmd.rules.naming;
+
+import org.apache.flex.pmd.nodes.IAttribute;
+import org.apache.flex.pmd.nodes.IConstant;
+import org.apache.flex.pmd.nodes.IFunction;
+import org.apache.flex.pmd.nodes.IVariable;
+import org.apache.flex.pmd.parser.IParserNode;
+import org.apache.flex.pmd.rules.core.AbstractAstFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map.Entry;
+
+/**
+ * @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/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/parameterized/ParameterizedRegExpBasedRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/parameterized/ParameterizedRegExpBasedRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/parameterized/ParameterizedRegExpBasedRule.java
new file mode 100644
index 0000000..f9ace2b
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/parameterized/ParameterizedRegExpBasedRule.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.flex.pmd.rules.parameterized;
+
+import net.sourceforge.pmd.lang.rule.properties.StringProperty;
+import org.apache.flex.pmd.rules.core.AbstractRegexpBasedRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+/**
+ * @author xagnetti
+ */
+public class ParameterizedRegExpBasedRule extends AbstractRegexpBasedRule {
+ private static final StringProperty EXPRESSION_DESCRIPTOR = new StringProperty(
+ "expression",
+ "",
+ "",
+ 1.0f
+ );
+
+ /*
+ * (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 getProperty(EXPRESSION_DESCRIPTOR);
+ }
+
+ /*
+ * (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/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/parsley/InaccessibleMetaDataRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/parsley/InaccessibleMetaDataRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/parsley/InaccessibleMetaDataRule.java
new file mode 100644
index 0000000..669c5c2
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/parsley/InaccessibleMetaDataRule.java
@@ -0,0 +1,85 @@
+/*
+ * 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 org.apache.flex.pmd.rules.parsley;
+
+import org.apache.flex.pmd.nodes.*;
+import org.apache.flex.pmd.rules.core.AbstractFlexMetaDataRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+import org.apache.flex.pmd.rules.parsley.utils.ParsleyMetaData;
+
+import java.util.List;
+
+/**
+ * @author xagnetti
+ */
+public final class InaccessibleMetaDataRule extends AbstractFlexMetaDataRule {
+ /*
+ * (non-Javadoc)
+ * @seecom.adobe.ac.pmd.rules.core.AbstractFlexMetaDataRule#
+ * findViolationsFromAttributeMetaData(com.adobe.ac.pmd.nodes.IAttribute)
+ */
+ @Override
+ protected void findViolationsFromAttributeMetaData(final IAttribute attribute) {
+ findInaccessibleNodes(attribute,
+ attribute);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @seecom.adobe.ac.pmd.rules.core.AbstractFlexMetaDataRule#
+ * findViolationsFromClassMetaData(com.adobe.ac.pmd.nodes.IClass)
+ */
+ @Override
+ protected void findViolationsFromClassMetaData(final IClass classNode) {
+ findInaccessibleNodes(classNode,
+ classNode);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @seecom.adobe.ac.pmd.rules.core.AbstractFlexMetaDataRule#
+ * findViolationsFromFunctionMetaData(com.adobe.ac.pmd.nodes.IFunction)
+ */
+ @Override
+ protected void findViolationsFromFunctionMetaData(final IFunction function) {
+ findInaccessibleNodes(function,
+ function);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority()
+ */
+ @Override
+ protected ViolationPriority getDefaultPriority() {
+ return ViolationPriority.NORMAL;
+ }
+
+ private void findInaccessibleNodes(final IMetaDataListHolder holder,
+ final IVisible visibility) {
+ final List<IMetaData> allMetaData = holder.getMetaData(MetaData.OTHER);
+
+ if (allMetaData != null) {
+ for (final IMetaData metaData : allMetaData) {
+ if (ParsleyMetaData.isParsleyMetaData(metaData.getName())
+ && !visibility.isPublic()) {
+ addViolation(metaData);
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/parsley/MessageInterceptorSignatureRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/parsley/MessageInterceptorSignatureRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/parsley/MessageInterceptorSignatureRule.java
new file mode 100644
index 0000000..725149e
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/parsley/MessageInterceptorSignatureRule.java
@@ -0,0 +1,81 @@
+/*
+ * 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 org.apache.flex.pmd.rules.parsley;
+
+import org.apache.flex.pmd.nodes.IFunction;
+import org.apache.flex.pmd.nodes.IMetaData;
+import org.apache.flex.pmd.nodes.IParameter;
+import org.apache.flex.pmd.parser.IParserNode;
+import org.apache.flex.pmd.rules.core.AbstractFlexMetaDataRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+import org.apache.flex.pmd.rules.parsley.utils.ParsleyMetaData;
+
+import java.util.List;
+
+/**
+ * @author xagnetti
+ */
+public final class MessageInterceptorSignatureRule extends AbstractFlexMetaDataRule {
+ /*
+ * (non-Javadoc)
+ * @seecom.adobe.ac.pmd.rules.core.AbstractFlexMetaDataRule#
+ * findViolationsFromFunctionMetaData(com.adobe.ac.pmd.nodes.IFunction)
+ */
+ @Override
+ protected void findViolationsFromFunctionMetaData(final IFunction function) {
+ final List<IMetaData> interceptors = ParsleyMetaData.MESSAGE_INTERCEPTOR.getMetaDataList(function);
+ final IParserNode name = getNameFromFunctionDeclaration(function.getInternalNode());
+
+ if (!interceptors.isEmpty()) {
+
+ if (!function.isPublic()) {
+ addViolation(name,
+ name,
+ name.getStringValue(),
+ "It is not public");
+ }
+ if (function.getParameters().size() == 1) {
+ if (!hasMessageProcessorParameter(function)) {
+ addViolation(name,
+ name,
+ name.getStringValue(),
+ "The argument type should be MessageProcessor");
+ }
+ } else {
+ addViolation(name,
+ name,
+ name.getStringValue(),
+ "Its argument number is not 1");
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority()
+ */
+ @Override
+ protected ViolationPriority getDefaultPriority() {
+ return ViolationPriority.NORMAL;
+ }
+
+ private boolean hasMessageProcessorParameter(final IFunction function) {
+ final IParameter param = function.getParameters().get(0);
+ final String type = param.getType().toString();
+ return "MessageProcessor".equals(type);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/parsley/MismatchedManagedEventRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/parsley/MismatchedManagedEventRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/parsley/MismatchedManagedEventRule.java
new file mode 100644
index 0000000..dbc0a83
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/parsley/MismatchedManagedEventRule.java
@@ -0,0 +1,78 @@
+/*
+ * 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 org.apache.flex.pmd.rules.parsley;
+
+import org.apache.flex.pmd.nodes.IClass;
+import org.apache.flex.pmd.nodes.IMetaData;
+import org.apache.flex.pmd.nodes.MetaData;
+import org.apache.flex.pmd.rules.core.AbstractFlexMetaDataRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+import org.apache.flex.pmd.rules.parsley.utils.ParsleyMetaData;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author xagnetti
+ */
+public final class MismatchedManagedEventRule extends AbstractFlexMetaDataRule {
+ /*
+ * (non-Javadoc)
+ * @seecom.adobe.ac.pmd.rules.core.AbstractFlexMetaDataRule#
+ * findViolationsFromClassMetaData(com.adobe.ac.pmd.nodes.IClass)
+ */
+ @Override
+ protected void findViolationsFromClassMetaData(final IClass classNode) {
+ final List<IMetaData> managedEvents = ParsleyMetaData.MANAGED_EVENTS.getMetaDataList(classNode);
+
+ final List<String> eventTypes = getEventTypes(classNode);
+
+ for (final IMetaData data : managedEvents) {
+ final List<String> types = data.getPropertyAsList("names");
+
+ for (final String type : types) {
+ if (!eventTypes.contains(type)) {
+ addViolation(data,
+ type);
+ }
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority()
+ */
+ @Override
+ protected ViolationPriority getDefaultPriority() {
+ return ViolationPriority.NORMAL;
+ }
+
+ private List<String> getEventTypes(final IClass classNode) {
+ final ArrayList<String> types = new ArrayList<String>();
+
+ for (final IMetaData data : classNode.getMetaData(MetaData.EVENT)) {
+ final String[] name = data.getProperty("name");
+ final String eventName = name.length == 0 ? data.getDefaultValue()
+ : name[0];
+
+ types.add(eventName);
+ }
+
+ return types;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/parsley/MisplacedMetaDataRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/parsley/MisplacedMetaDataRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/parsley/MisplacedMetaDataRule.java
new file mode 100644
index 0000000..2100f17
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/parsley/MisplacedMetaDataRule.java
@@ -0,0 +1,102 @@
+/*
+ * 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 org.apache.flex.pmd.rules.parsley;
+
+import org.apache.flex.pmd.nodes.*;
+import org.apache.flex.pmd.rules.core.AbstractFlexMetaDataRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+import org.apache.flex.pmd.rules.parsley.utils.MetaDataTag;
+import org.apache.flex.pmd.rules.parsley.utils.ParsleyMetaData;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author xagnetti
+ */
+public final class MisplacedMetaDataRule extends AbstractFlexMetaDataRule {
+ /*
+ * (non-Javadoc)
+ * @seecom.adobe.ac.pmd.rules.core.AbstractFlexMetaDataRule#
+ * findViolationsFromAttributeMetaData(com.adobe.ac.pmd.nodes.IAttribute)
+ */
+ @Override
+ protected void findViolationsFromAttributeMetaData(final IAttribute attribute) {
+ findDisallowedMetaData(attribute,
+ MetaDataTag.Location.ATTRIBUTE);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @seecom.adobe.ac.pmd.rules.core.AbstractFlexMetaDataRule#
+ * findViolationsFromClassMetaData(com.adobe.ac.pmd.nodes.IClass)
+ */
+ @Override
+ protected void findViolationsFromClassMetaData(final IClass classNode) {
+ findDisallowedMetaData(classNode,
+ MetaDataTag.Location.CLASS_DECLARATION);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @seecom.adobe.ac.pmd.rules.core.AbstractFlexMetaDataRule#
+ * findViolationsFromFunctionMetaData(com.adobe.ac.pmd.nodes.IFunction)
+ */
+ @Override
+ protected void findViolationsFromFunctionMetaData(final IFunction function) {
+ findDisallowedMetaData(function,
+ MetaDataTag.Location.FUNCTION);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority()
+ */
+ @Override
+ protected ViolationPriority getDefaultPriority() {
+ return ViolationPriority.NORMAL;
+ }
+
+ private void findDisallowedMetaData(final IMetaDataListHolder holder,
+ final MetaDataTag.Location location) {
+ final List<String> tags = getDisallowedTags(location);
+ final List<IMetaData> otherMetadata = holder.getMetaData(MetaData.OTHER);
+
+ if (otherMetadata == null) {
+ return;
+ }
+
+ for (final IMetaData metaData : otherMetadata) {
+ if (tags.contains(metaData.getName())) {
+ addViolation(metaData,
+ metaData.getName());
+ }
+ }
+ }
+
+ private List<String> getDisallowedTags(final MetaDataTag.Location location) {
+ final List<String> tags = new ArrayList<String>();
+
+ for (final MetaDataTag tag : ParsleyMetaData.ALL_TAGS) {
+ if (!tag.getPlacedOn().contains(location)) {
+ tags.add(tag.getName());
+ }
+ }
+
+ return tags;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/parsley/RedundantMessageHandlerTypeAttributeRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/parsley/RedundantMessageHandlerTypeAttributeRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/parsley/RedundantMessageHandlerTypeAttributeRule.java
new file mode 100644
index 0000000..cda1cfd
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/parsley/RedundantMessageHandlerTypeAttributeRule.java
@@ -0,0 +1,89 @@
+/*
+ * 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 org.apache.flex.pmd.rules.parsley;
+
+import org.apache.flex.pmd.nodes.IFunction;
+import org.apache.flex.pmd.nodes.IIdentifierNode;
+import org.apache.flex.pmd.nodes.IMetaData;
+import org.apache.flex.pmd.nodes.IParameter;
+import org.apache.flex.pmd.rules.core.AbstractFlexMetaDataRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+import org.apache.flex.pmd.rules.parsley.utils.ParsleyMetaData;
+
+import java.util.List;
+
+/**
+ * @author xagnetti
+ */
+public final class RedundantMessageHandlerTypeAttributeRule extends AbstractFlexMetaDataRule {
+ /*
+ * (non-Javadoc)
+ * @seecom.adobe.ac.pmd.rules.core.AbstractFlexMetaDataRule#
+ * findViolationsFromFunctionMetaData(com.adobe.ac.pmd.nodes.IFunction)
+ */
+ @Override
+ protected void findViolationsFromFunctionMetaData(final IFunction function) {
+ final List<IParameter> params = function.getParameters();
+
+ if (params.size() == 1) {
+ final IIdentifierNode parameterType = params.get(0).getType();
+ findMessageHandlersContainingType(function,
+ parameterType);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority()
+ */
+ @Override
+ protected ViolationPriority getDefaultPriority() {
+ return ViolationPriority.NORMAL;
+ }
+
+ private void findMessageHandlersContainingType(final IFunction function,
+ final IIdentifierNode type) {
+ final List<IMetaData> handlers = ParsleyMetaData.MESSAGE_HANDLER.getMetaDataList(function);
+
+ for (final IMetaData handler : handlers) {
+ final String parameterType = type.toString();
+ final String metaDataType = getMessageHandlerType(handler);
+
+ if (metaDataType != null
+ && metaDataType.equals(parameterType)) {
+ addViolation(handler);
+ }
+ }
+ }
+
+ private String getMessageHandlerType(final IMetaData handler) {
+ final String[] types = handler.getProperty("type");
+ String type = "";
+
+ if (types.length > 0
+ && types[0].contains(".")) {
+ type = types[0];
+ final int index = type.lastIndexOf('.') + 1;
+
+ if (index < type.length()) {
+ type = type.substring(index);
+ }
+ }
+
+ return type;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/parsley/RedundantMethodAttributeRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/parsley/RedundantMethodAttributeRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/parsley/RedundantMethodAttributeRule.java
new file mode 100644
index 0000000..914b849
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/parsley/RedundantMethodAttributeRule.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.flex.pmd.rules.parsley;
+
+import org.apache.flex.pmd.nodes.IFunction;
+import org.apache.flex.pmd.nodes.IMetaData;
+import org.apache.flex.pmd.nodes.MetaData;
+import org.apache.flex.pmd.rules.core.AbstractFlexMetaDataRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+import org.apache.flex.pmd.rules.parsley.utils.MetaDataTag;
+import org.apache.flex.pmd.rules.parsley.utils.ParsleyMetaData;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author xagnetti
+ */
+public final class RedundantMethodAttributeRule extends AbstractFlexMetaDataRule {
+ /*
+ * (non-Javadoc)
+ * @seecom.adobe.ac.pmd.rules.core.AbstractFlexMetaDataRule#
+ * findViolationsFromFunctionMetaData(com.adobe.ac.pmd.nodes.IFunction)
+ */
+ @Override
+ protected void findViolationsFromFunctionMetaData(final IFunction function) {
+ final List<IMetaData> metaData = function.getMetaData(MetaData.OTHER);
+ final List<String> parsleyTags = getTagsForFunctions();
+
+ for (final IMetaData md : metaData) {
+ if (parsleyTags.contains(md.getName())
+ && md.getAttributeNames().contains("method")) {
+ addViolation(md);
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority()
+ */
+ @Override
+ protected ViolationPriority getDefaultPriority() {
+ return ViolationPriority.NORMAL;
+ }
+
+ private List<String> getTagsForFunctions() {
+ final List<String> tags = new ArrayList<String>();
+
+ for (final MetaDataTag tag : ParsleyMetaData.ALL_TAGS) {
+ if (tag.getPlacedOn().contains(MetaDataTag.Location.FUNCTION)) {
+ tags.add(tag.getName());
+ }
+ }
+
+ return tags;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/parsley/UnknownMetaDataAttributeRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/parsley/UnknownMetaDataAttributeRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/parsley/UnknownMetaDataAttributeRule.java
new file mode 100644
index 0000000..3453f0f
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/parsley/UnknownMetaDataAttributeRule.java
@@ -0,0 +1,71 @@
+/*
+ * 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 org.apache.flex.pmd.rules.parsley;
+
+import org.apache.flex.pmd.nodes.IMetaData;
+import org.apache.flex.pmd.nodes.IMetaDataListHolder;
+import org.apache.flex.pmd.nodes.MetaData;
+import org.apache.flex.pmd.rules.core.AbstractFlexMetaDataRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+import org.apache.flex.pmd.rules.parsley.utils.MetaDataTag;
+import org.apache.flex.pmd.rules.parsley.utils.ParsleyMetaData;
+
+import java.util.List;
+
+/**
+ * @author xagnetti
+ */
+public final class UnknownMetaDataAttributeRule extends AbstractFlexMetaDataRule {
+ /*
+ * (non-Javadoc)
+ * @seecom.adobe.ac.pmd.rules.core.AbstractFlexMetaDataRule#
+ * findViolationsFromMetaDataList(com.adobe.ac.pmd.nodes.IMetaDataListHolder)
+ */
+ @Override
+ protected void findViolationsFromMetaDataList(final IMetaDataListHolder holder) {
+ final List<IMetaData> items = holder.getMetaData(MetaData.OTHER);
+
+ if (items == null) {
+ return;
+ }
+
+ for (final IMetaData metaData : items) {
+ final MetaDataTag tag = ParsleyMetaData.getTag(metaData.getName());
+
+ if (tag != null) {
+ final List<String> known = tag.getAttributes();
+ final List<String> actual = metaData.getAttributeNames();
+
+ for (final String actualAttribute : actual) {
+ if (!known.contains(actualAttribute)) {
+ addViolation(metaData,
+ actualAttribute);
+ }
+ }
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority()
+ */
+ @Override
+ protected ViolationPriority getDefaultPriority() {
+ return ViolationPriority.HIGH;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/parsley/utils/MetaDataTag.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/parsley/utils/MetaDataTag.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/parsley/utils/MetaDataTag.java
new file mode 100644
index 0000000..3971f3c
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/parsley/utils/MetaDataTag.java
@@ -0,0 +1,95 @@
+/*
+ * 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 org.apache.flex.pmd.rules.parsley.utils;
+
+import org.apache.flex.pmd.nodes.IMetaData;
+import org.apache.flex.pmd.nodes.IMetaDataListHolder;
+import org.apache.flex.pmd.nodes.MetaData;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * @author xagnetti
+ */
+public final class MetaDataTag {
+ /**
+ * @author xagnetti
+ */
+ public enum Location {
+ ATTRIBUTE, CLASS_DECLARATION, FUNCTION
+ }
+
+ ;
+
+ private final String[] attributes;
+
+ private final String name;
+
+ private final Location[] placedOn;
+
+ /**
+ * @param nameToBeSet
+ * @param attributesToBeSet
+ * @param placedOnToBeSet
+ */
+ public MetaDataTag(final String nameToBeSet,
+ final String[] attributesToBeSet,
+ final Location[] placedOnToBeSet) {
+ name = nameToBeSet;
+ attributes = attributesToBeSet;
+ placedOn = placedOnToBeSet;
+ }
+
+ /**
+ * @return
+ */
+ public List<String> getAttributes() {
+ return Arrays.asList(attributes);
+ }
+
+ /**
+ * @param holder
+ * @return
+ */
+ public List<IMetaData> getMetaDataList(final IMetaDataListHolder holder) {
+ final List<IMetaData> list = new ArrayList<IMetaData>();
+
+ for (final IMetaData metaData : holder.getMetaData(MetaData.OTHER)) {
+ if (metaData.getName().equals(name)) {
+ list.add(metaData);
+ }
+ }
+
+ return list;
+ }
+
+ /**
+ * @return
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @return
+ */
+ public List<Location> getPlacedOn() {
+ return Arrays.asList(placedOn);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/parsley/utils/ParsleyMetaData.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/parsley/utils/ParsleyMetaData.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/parsley/utils/ParsleyMetaData.java
new file mode 100644
index 0000000..2f69e57
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/parsley/utils/ParsleyMetaData.java
@@ -0,0 +1,266 @@
+/*
+ * 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 org.apache.flex.pmd.rules.parsley.utils;
+
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+public final class ParsleyMetaData {
+ private ParsleyMetaData() {
+ super();
+ }
+
+ private static final String KEY = "key";
+
+ private static final String BUNDLE = "bundle";
+
+ private static final String ORDER = "order";
+
+ private static final String SINGLETON = "singleton";
+
+ private static final String LAZY = "lazy";
+
+ private static final String MESSAGE_PROPERTIES = "messageProperties";
+
+ private static final String PROPERTY = "property";
+
+ private static final String TARGET_PROPERTY = "targetProperty";
+
+ private static final String SCOPE = "scope";
+
+ private static final String REQUIRED = "required";
+
+ private static final String ERROR_EVENT = "errorEvent";
+
+ private static final String COMPLETE_EVENT = "completeEvent";
+
+ private static final String SELECTOR2 = "selector";
+
+ private static final String MESSAGE_PROPERTY = "messageProperty";
+
+ private static final String TYPE = "type";
+
+ private static final String NAMES = "names";
+
+ private static final String ID_PROPERTY = "id";
+
+ private static final String METHOD = "method";
+
+ private static final MetaDataTag.Location[] CLASS_LOCATION = new MetaDataTag.Location[]
+ {MetaDataTag.Location.CLASS_DECLARATION};
+
+ private static final MetaDataTag.Location[] FUNCTION_LOCATION = new MetaDataTag.Location[]
+ {MetaDataTag.Location.FUNCTION};
+
+ private static final MetaDataTag.Location[] ATTR_FCTION_LOCATION = new MetaDataTag.Location[]
+ {MetaDataTag.Location.ATTRIBUTE,
+ MetaDataTag.Location.FUNCTION};
+
+ private static final MetaDataTag.Location[] ATTRIBUTE_LOCATION = new MetaDataTag.Location[]
+ {MetaDataTag.Location.ATTRIBUTE};
+
+ public static final MetaDataTag ASYNC_INIT = new MetaDataTag("AsyncInit",
+ new String[]
+ {COMPLETE_EVENT,
+ ERROR_EVENT},
+ CLASS_LOCATION);
+
+ public static final MetaDataTag COMMAND_COMPLETE = new MetaDataTag("CommandComplete",
+ new String[]
+ {},
+ FUNCTION_LOCATION);
+
+ public static final MetaDataTag DESTROY = new MetaDataTag("Destroy",
+ new String[]
+ {METHOD},
+ FUNCTION_LOCATION);
+
+ public static final MetaDataTag FACTORY = new MetaDataTag("Factory",
+ new String[]
+ {METHOD},
+ FUNCTION_LOCATION);
+
+ public static final MetaDataTag INIT = new MetaDataTag("Init",
+ new String[]
+ {METHOD},
+ FUNCTION_LOCATION);
+
+ public static final MetaDataTag INJECT = new MetaDataTag("Inject",
+ new String[]
+ {ID_PROPERTY,
+ REQUIRED},
+ ATTR_FCTION_LOCATION);
+
+ public static final MetaDataTag INJECT_CONSTRUCTOR = new MetaDataTag("InjectConstructor",
+ new String[]
+ {},
+ CLASS_LOCATION);
+
+ public static final MetaDataTag INTERNAL = new MetaDataTag("Internal",
+ new String[]
+ {},
+ ATTRIBUTE_LOCATION);
+
+ public static final MetaDataTag MANAGED_EVENTS = new MetaDataTag("ManagedEvents",
+ new String[]
+ {NAMES,
+ SCOPE},
+ CLASS_LOCATION);
+
+ public static final MetaDataTag MESSAGE_BINDING = new MetaDataTag("MessageBinding",
+ new String[]
+ {TYPE,
+ MESSAGE_PROPERTY,
+ SELECTOR2,
+ SCOPE,
+ TARGET_PROPERTY},
+ ATTRIBUTE_LOCATION);
+
+ public static final MetaDataTag MESSAGE_DISPATCHER = new MetaDataTag("MessageDispatcher",
+ new String[]
+ {PROPERTY,
+ SCOPE},
+ ATTRIBUTE_LOCATION);
+
+ public static final MetaDataTag MESSAGE_ERROR = new MetaDataTag("MessageError",
+ new String[]
+ {TYPE,
+ SELECTOR2,
+ SCOPE,
+ METHOD},
+ FUNCTION_LOCATION);
+
+ public static final MetaDataTag MESSAGE_HANDLER = new MetaDataTag("MessageHandler",
+ new String[]
+ {TYPE,
+ MESSAGE_PROPERTIES,
+ SELECTOR2,
+ SCOPE,
+ METHOD},
+ FUNCTION_LOCATION);
+
+ public static final MetaDataTag MESSAGE_INTERCEPTOR = new MetaDataTag("MessageInterceptor",
+ new String[]
+ {TYPE,
+ SELECTOR2,
+ SCOPE,
+ METHOD},
+ FUNCTION_LOCATION);
+
+ public static final MetaDataTag OBJECT_DEFINITION = new MetaDataTag("ObjectDefinition",
+ new String[]
+ {LAZY,
+ SINGLETON,
+ ID_PROPERTY,
+ ORDER},
+ ATTRIBUTE_LOCATION);
+
+ public static final MetaDataTag RESOURCE_BINDING = new MetaDataTag("ResourceBinding",
+ new String[]
+ {BUNDLE,
+ KEY,
+ PROPERTY},
+ ATTRIBUTE_LOCATION);
+
+ public static final MetaDataTag SELECTOR = new MetaDataTag("Selector",
+ new String[]
+ {},
+ ATTRIBUTE_LOCATION);
+
+ public static final MetaDataTag TARGET = new MetaDataTag("Target",
+ new String[]
+ {},
+ ATTRIBUTE_LOCATION);
+
+ public static final MetaDataTag[] ALL_TAGS =
+ {INJECT,
+ INJECT_CONSTRUCTOR,
+ MANAGED_EVENTS,
+ MESSAGE_BINDING,
+ MESSAGE_DISPATCHER,
+ MESSAGE_ERROR,
+ MESSAGE_HANDLER,
+ MESSAGE_INTERCEPTOR,
+ COMMAND_COMPLETE,
+ ASYNC_INIT,
+ INIT,
+ DESTROY,
+ RESOURCE_BINDING,
+ FACTORY,
+ OBJECT_DEFINITION,
+ TARGET,
+ INTERNAL};
+
+ private static final Map<String, MetaDataTag> TAG_MAP = new LinkedHashMap<String, MetaDataTag>();
+
+ static {
+ TAG_MAP.put(INJECT.getName(),
+ INJECT);
+ TAG_MAP.put(COMMAND_COMPLETE.getName(),
+ COMMAND_COMPLETE);
+ TAG_MAP.put(INJECT_CONSTRUCTOR.getName(),
+ INJECT_CONSTRUCTOR);
+ TAG_MAP.put(MANAGED_EVENTS.getName(),
+ MANAGED_EVENTS);
+ TAG_MAP.put(MESSAGE_BINDING.getName(),
+ MESSAGE_BINDING);
+ TAG_MAP.put(MESSAGE_DISPATCHER.getName(),
+ MESSAGE_DISPATCHER);
+ TAG_MAP.put(MESSAGE_ERROR.getName(),
+ MESSAGE_ERROR);
+ TAG_MAP.put(MESSAGE_HANDLER.getName(),
+ MESSAGE_HANDLER);
+ TAG_MAP.put(MESSAGE_INTERCEPTOR.getName(),
+ MESSAGE_INTERCEPTOR);
+ TAG_MAP.put(ASYNC_INIT.getName(),
+ ASYNC_INIT);
+ TAG_MAP.put(INIT.getName(),
+ INIT);
+ TAG_MAP.put(DESTROY.getName(),
+ DESTROY);
+ TAG_MAP.put(RESOURCE_BINDING.getName(),
+ RESOURCE_BINDING);
+ TAG_MAP.put(FACTORY.getName(),
+ FACTORY);
+ TAG_MAP.put(OBJECT_DEFINITION.getName(),
+ OBJECT_DEFINITION);
+ TAG_MAP.put(TARGET.getName(),
+ TARGET);
+ TAG_MAP.put(INTERNAL.getName(),
+ INTERNAL);
+ }
+
+ public static MetaDataTag getTag(final String name) {
+ return TAG_MAP.get(name);
+ }
+
+ public static boolean isParsleyMetaData(final String name) {
+ return TAG_MAP.containsKey(name);
+ }
+
+ public static Map<String, MetaDataTag> getPossibleMetaDataFromLocation(MetaDataTag.Location location) {
+ Map<String, MetaDataTag> tags = new HashMap<String, MetaDataTag>();
+
+ for (MetaDataTag metaDataTag : ALL_TAGS) {
+ if (metaDataTag.getPlacedOn().contains(location)) {
+ tags.put(metaDataTag.getName(), metaDataTag);
+ }
+ }
+ return tags;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/performance/AbstractAvoidNodeInLoopRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/performance/AbstractAvoidNodeInLoopRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/performance/AbstractAvoidNodeInLoopRule.java
new file mode 100644
index 0000000..ad1d81a
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/performance/AbstractAvoidNodeInLoopRule.java
@@ -0,0 +1,74 @@
+/*
+ * 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 org.apache.flex.pmd.rules.performance;
+
+import org.apache.flex.pmd.parser.IParserNode;
+import org.apache.flex.pmd.parser.NodeKind;
+import org.apache.flex.pmd.rules.core.AbstractAstFlexRule;
+
+public abstract class AbstractAvoidNodeInLoopRule extends AbstractAstFlexRule {
+ private int loopLevel = 0;
+
+ protected int getLoopLevel() {
+ return loopLevel;
+ }
+
+ protected abstract boolean isNodeForbidden(final IParserNode ast);
+
+ @Override
+ protected final void visitFor(final IParserNode ast) {
+ loopLevel++;
+ super.visitFor(ast);
+ loopLevel--;
+ }
+
+ @Override
+ protected final void visitForEach(final IParserNode ast) {
+ loopLevel++;
+ super.visitForEach(ast);
+ loopLevel--;
+ }
+
+ @Override
+ protected final void visitStatement(final IParserNode ast) {
+ super.visitStatement(ast);
+
+ if (ast != null
+ && !ast.is(NodeKind.WHILE) && !ast.is(NodeKind.FOR) && !ast.is(NodeKind.FOREACH)
+ && !ast.is(NodeKind.FOR)) {
+ searchForbiddenNode(ast);
+ }
+ }
+
+ @Override
+ protected final void visitWhile(final IParserNode ast) {
+ loopLevel++;
+ super.visitWhile(ast);
+ loopLevel--;
+ }
+
+ private void searchForbiddenNode(final IParserNode ast) {
+ if (ast.numChildren() > 0) {
+ for (final IParserNode child : ast.getChildren()) {
+ searchForbiddenNode(child);
+ }
+ }
+ if (isNodeForbidden(ast)) {
+ addViolation(ast);
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/performance/AvoidDeclarationInLoopRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/performance/AvoidDeclarationInLoopRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/performance/AvoidDeclarationInLoopRule.java
new file mode 100644
index 0000000..d7d38d0
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/performance/AvoidDeclarationInLoopRule.java
@@ -0,0 +1,34 @@
+/*
+ * 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 org.apache.flex.pmd.rules.performance;
+
+import org.apache.flex.pmd.parser.IParserNode;
+import org.apache.flex.pmd.parser.NodeKind;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+public class AvoidDeclarationInLoopRule extends AbstractAvoidNodeInLoopRule {
+ @Override
+ protected ViolationPriority getDefaultPriority() {
+ return ViolationPriority.NORMAL;
+ }
+
+ @Override
+ protected boolean isNodeForbidden(final IParserNode ast) {
+ return ast.getId() != null
+ && (ast.is(NodeKind.VAR) || ast.is(NodeKind.VAR_LIST)) && getLoopLevel() != 0;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/performance/AvoidInstanciationInLoopRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/performance/AvoidInstanciationInLoopRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/performance/AvoidInstanciationInLoopRule.java
new file mode 100644
index 0000000..2e14499
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/performance/AvoidInstanciationInLoopRule.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 org.apache.flex.pmd.rules.performance;
+
+import org.apache.flex.pmd.parser.IParserNode;
+import org.apache.flex.pmd.parser.NodeKind;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+/**
+ * @author xagnetti
+ */
+public class AvoidInstanciationInLoopRule extends AbstractAvoidNodeInLoopRule {
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority()
+ */
+ @Override
+ protected final ViolationPriority getDefaultPriority() {
+ return ViolationPriority.NORMAL;
+ }
+
+ @Override
+ protected boolean isNodeForbidden(final IParserNode ast) {
+ return ast.getId() != null
+ && ast.is(NodeKind.NEW) && getLoopLevel() != 0;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/performance/AvoidUsingMathCeilRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/performance/AvoidUsingMathCeilRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/performance/AvoidUsingMathCeilRule.java
new file mode 100644
index 0000000..ee4c96c
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/performance/AvoidUsingMathCeilRule.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 org.apache.flex.pmd.rules.performance;
+
+import org.apache.flex.pmd.nodes.IFunction;
+import org.apache.flex.pmd.parser.IParserNode;
+import org.apache.flex.pmd.rules.core.AbstractPrimaryAstRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+/**
+ * @author xagnetti
+ */
+public class AvoidUsingMathCeilRule extends AbstractPrimaryAstRule {
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractPrimaryAstRule#addViolation(com.adobe
+ * .ac.pmd.parser.IParserNode, com.adobe.ac.pmd.nodes.IFunction)
+ */
+ @Override
+ protected void addViolation(final IParserNode statement,
+ final IFunction function) {
+ addViolation(statement);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority()
+ */
+ @Override
+ protected ViolationPriority getDefaultPriority() {
+ return ViolationPriority.LOW;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractPrimaryAstRule#getFirstPrimaryToFind()
+ */
+ @Override
+ protected String getFirstPrimaryToFind() {
+ return "Math";
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractPrimaryAstRule#getSecondPrimaryToFind
+ * ()
+ */
+ @Override
+ protected String getSecondPrimaryToFind() {
+ return "ceil";
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/performance/AvoidUsingMathFloorRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/performance/AvoidUsingMathFloorRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/performance/AvoidUsingMathFloorRule.java
new file mode 100644
index 0000000..45028ba
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/performance/AvoidUsingMathFloorRule.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 org.apache.flex.pmd.rules.performance;
+
+import org.apache.flex.pmd.nodes.IFunction;
+import org.apache.flex.pmd.parser.IParserNode;
+import org.apache.flex.pmd.rules.core.AbstractPrimaryAstRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+/**
+ * @author xagnetti
+ */
+public class AvoidUsingMathFloorRule extends AbstractPrimaryAstRule {
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractPrimaryAstRule#addViolation(com.adobe
+ * .ac.pmd.parser.IParserNode, com.adobe.ac.pmd.nodes.IFunction)
+ */
+ @Override
+ protected void addViolation(final IParserNode statement,
+ final IFunction function) {
+ addViolation(statement);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority()
+ */
+ @Override
+ protected ViolationPriority getDefaultPriority() {
+ return ViolationPriority.LOW;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractPrimaryAstRule#getFirstPrimaryToFind()
+ */
+ @Override
+ protected String getFirstPrimaryToFind() {
+ return "Math";
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractPrimaryAstRule#getSecondPrimaryToFind
+ * ()
+ */
+ @Override
+ protected String getSecondPrimaryToFind() {
+ return "floor";
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/performance/AvoidUsingMathRoundRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/performance/AvoidUsingMathRoundRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/performance/AvoidUsingMathRoundRule.java
new file mode 100644
index 0000000..4ccad25
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/performance/AvoidUsingMathRoundRule.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 org.apache.flex.pmd.rules.performance;
+
+import org.apache.flex.pmd.nodes.IFunction;
+import org.apache.flex.pmd.parser.IParserNode;
+import org.apache.flex.pmd.rules.core.AbstractPrimaryAstRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+/**
+ * @author xagnetti
+ */
+public class AvoidUsingMathRoundRule extends AbstractPrimaryAstRule {
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractPrimaryAstRule#addViolation(com.adobe
+ * .ac.pmd.parser.IParserNode, com.adobe.ac.pmd.nodes.IFunction)
+ */
+ @Override
+ protected void addViolation(final IParserNode statement,
+ final IFunction function) {
+ addViolation(statement);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority()
+ */
+ @Override
+ protected ViolationPriority getDefaultPriority() {
+ return ViolationPriority.LOW;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractPrimaryAstRule#getFirstPrimaryToFind()
+ */
+ @Override
+ protected String getFirstPrimaryToFind() {
+ return "Math";
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractPrimaryAstRule#getSecondPrimaryToFind
+ * ()
+ */
+ @Override
+ protected String getSecondPrimaryToFind() {
+ return "round";
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/performance/BindableClassRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/performance/BindableClassRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/performance/BindableClassRule.java
new file mode 100644
index 0000000..7ffe6c4
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/performance/BindableClassRule.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 org.apache.flex.pmd.rules.performance;
+
+import org.apache.flex.pmd.nodes.IClass;
+import org.apache.flex.pmd.nodes.MetaData;
+import org.apache.flex.pmd.rules.core.AbstractAstFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+/**
+ * @author xagnetti
+ */
+public class BindableClassRule extends AbstractAstFlexRule {
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#isConcernedByTheCurrentFile
+ * ()
+ */
+ @Override
+ public final boolean isConcernedByTheCurrentFile() {
+ return !getCurrentFile().isMxml()
+ && !getCurrentFile().getClassName().endsWith("VO.as");
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#findViolations(com.adobe
+ * .ac.pmd.nodes.IClass)
+ */
+ @Override
+ protected final void findViolations(final IClass classNode) {
+ if (classNode.isBindable()) {
+ addViolation(classNode.getMetaData(MetaData.BINDABLE).get(0));
+ }
+ }
+
+ /*
+ * (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/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/performance/CreationPolicySetToAllRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/performance/CreationPolicySetToAllRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/performance/CreationPolicySetToAllRule.java
new file mode 100644
index 0000000..6a21a15
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/performance/CreationPolicySetToAllRule.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.flex.pmd.rules.performance;
+
+import org.apache.flex.pmd.rules.core.AbstractRegexpBasedRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+import java.util.Locale;
+
+/**
+ * @author xagnetti
+ */
+public class CreationPolicySetToAllRule extends AbstractRegexpBasedRule {
+ /*
+ * (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.NORMAL;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.rules.core.AbstractRegexpBasedRule#getRegexp()
+ */
+ @Override
+ protected final String getRegexp() {
+ return ".*creationPolicy.*";
+ }
+
+ /*
+ * (non-Javadoc)
+ * @seecom.adobe.ac.pmd.rules.core.AbstractRegexpBasedRule#
+ * isViolationDetectedOnThisMatchingLine(java.lang.String)
+ */
+ @Override
+ protected final boolean isViolationDetectedOnThisMatchingLine(final String line) {
+ return line.toLowerCase(Locale.FRANCE).contains("all");
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/performance/CyclomaticComplexityRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/performance/CyclomaticComplexityRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/performance/CyclomaticComplexityRule.java
new file mode 100644
index 0000000..9788951
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/performance/CyclomaticComplexityRule.java
@@ -0,0 +1,71 @@
+/*
+ * 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 org.apache.flex.pmd.rules.performance;
+
+import org.apache.flex.pmd.nodes.IFunction;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+import org.apache.flex.pmd.rules.core.thresholded.AbstractMaximizedAstFlexRule;
+
+/**
+ * @author xagnetti
+ */
+public class CyclomaticComplexityRule extends AbstractMaximizedAstFlexRule {
+ public static final int DEFAULT_THRESHOLD = 10;
+ private IFunction currentFunction = null;
+
+ /*
+ * (non-Javadoc)
+ * @seecom.adobe.ac.pmd.rules.core.thresholded.IThresholdedRule#
+ * getActualValueForTheCurrentViolation()
+ */
+ public final int getActualValueForTheCurrentViolation() {
+ return currentFunction.getCyclomaticComplexity();
+ }
+
+ /*
+ * (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.AbstractAstFlexRule#findViolations(com.adobe
+ * .ac.pmd.nodes.IFunction)
+ */
+ @Override
+ protected final void findViolations(final IFunction function) {
+ currentFunction = function;
+ if (function.getCyclomaticComplexity() > getThreshold()) {
+ addViolation(function);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority()
+ */
+ @Override
+ protected final ViolationPriority getDefaultPriority() {
+ return ViolationPriority.HIGH;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/performance/DeeplyNestedIfRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/performance/DeeplyNestedIfRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/performance/DeeplyNestedIfRule.java
new file mode 100644
index 0000000..b39e743
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/performance/DeeplyNestedIfRule.java
@@ -0,0 +1,113 @@
+/*
+ * 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 org.apache.flex.pmd.rules.performance;
+
+import org.apache.flex.pmd.parser.IParserNode;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+import org.apache.flex.pmd.rules.core.thresholded.AbstractMaximizedAstFlexRule;
+
+/**
+ * @author xagnetti
+ */
+public class DeeplyNestedIfRule extends AbstractMaximizedAstFlexRule {
+ private int ifLevel = 0;
+
+ /*
+ * (non-Javadoc)
+ * @seecom.adobe.ac.pmd.rules.core.thresholded.IThresholdedRule#
+ * getActualValueForTheCurrentViolation()
+ */
+ public final int getActualValueForTheCurrentViolation() {
+ return ifLevel;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.thresholded.IThresholdedRule#getDefaultThreshold
+ * ()
+ */
+ public final int getDefaultThreshold() {
+ return 2;
+ }
+
+ /*
+ * (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#visitElse(com.adobe.ac
+ * .pmd.parser.IParserNode)
+ */
+ @Override
+ protected final void visitElse(final IParserNode ifNode) {
+ beforeVisitingIfBlock();
+
+ super.visitElse(ifNode);
+
+ afterVisitingIfBlock(ifNode);
+ }
+
+ /*
+ * (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) {
+ ifLevel = 0;
+
+ super.visitFunction(ast,
+ type);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#visitThen(com.adobe.ac
+ * .pmd.parser.IParserNode)
+ */
+ @Override
+ protected final void visitThen(final IParserNode ifNode) {
+ beforeVisitingIfBlock();
+
+ super.visitThen(ifNode);
+
+ afterVisitingIfBlock(ifNode);
+ }
+
+ private void afterVisitingIfBlock(final IParserNode ifNode) {
+ ifLevel--;
+ if (ifLevel >= getThreshold()) {
+ addViolation(ifNode);
+ }
+ }
+
+ private void beforeVisitingIfBlock() {
+ ifLevel++;
+ }
+}
[17/24] git commit: [flex-utilities]
[refs/heads/feature/pmd-5.2-language-module] - Initial commit of the PMD
language module for Apache Flex
Posted by cd...@apache.org.
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/impl/FunctionNode.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/impl/FunctionNode.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/impl/FunctionNode.java
new file mode 100644
index 0000000..5fdc916
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/impl/FunctionNode.java
@@ -0,0 +1,367 @@
+/*
+ * 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 org.apache.flex.pmd.nodes.impl;
+
+import org.apache.flex.pmd.nodes.*;
+import org.apache.flex.pmd.parser.IParserNode;
+import org.apache.flex.pmd.parser.KeyWords;
+import org.apache.flex.pmd.parser.NodeKind;
+
+import java.util.*;
+import java.util.Map.Entry;
+
+/**
+ * @author xagnetti
+ */
+class FunctionNode extends AbstractNode implements IFunction {
+ private IParserNode asDoc;
+ private IParserNode body;
+ private int cyclomaticComplexity;
+ private final Map<String, IParserNode> localVariables;
+ private final Map<MetaData, List<IMetaData>> metaDataList;
+ private final Set<Modifier> modifiers;
+ private final List<IParserNode> multiLinesComments;
+ private IdentifierNode name;
+ private final List<IParameter> parameters;
+ private IIdentifierNode returnType;
+
+ /**
+ * @param node
+ */
+ protected FunctionNode(final IParserNode node) {
+ super(node);
+
+ modifiers = new HashSet<Modifier>();
+ metaDataList = new LinkedHashMap<MetaData, List<IMetaData>>();
+ localVariables = new LinkedHashMap<String, IParserNode>();
+ parameters = new ArrayList<IParameter>();
+ name = null;
+ multiLinesComments = new ArrayList<IParserNode>();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.nodes.IMetaDataListHolder#add(com.adobe.ac.pmd.nodes.
+ * IMetaData)
+ */
+ public void add(final IMetaData metaData) {
+ final MetaData metaDataImpl = MetaData.create(metaData.getName());
+
+ if (!metaDataList.containsKey(metaDataImpl)) {
+ metaDataList.put(metaDataImpl,
+ new ArrayList<IMetaData>());
+ }
+ metaDataList.get(metaDataImpl).add(metaData);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.nodes.IModifiersHolder#add(com.adobe.ac.pmd.nodes.Modifier
+ * )
+ */
+ public void add(final Modifier modifier) {
+ modifiers.add(modifier);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.impl.AbstractNode#compute()
+ */
+ @Override
+ public FunctionNode compute() {
+ if (getInternalNode().numChildren() != 0) {
+ for (final IParserNode node : getInternalNode().getChildren()) {
+ if (node.is(NodeKind.BLOCK)) {
+ computeFunctionContent(node);
+ } else if (node.is(NodeKind.NAME)) {
+ name = IdentifierNode.create(node);
+ } else if (node.is(NodeKind.MOD_LIST)) {
+ computeModifierList(this,
+ node);
+ } else if (node.is(NodeKind.PARAMETER_LIST)) {
+ computeParameterList(node);
+ } else if (node.is(NodeKind.TYPE)) {
+ returnType = IdentifierNode.create(node);
+ } else if (node.is(NodeKind.META_LIST)) {
+ computeMetaDataList(this,
+ node);
+ } else if (node.is(NodeKind.AS_DOC)) {
+ asDoc = node;
+ }
+ }
+ }
+ return this;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.nodes.IFunction#findPrimaryStatementInBody(java.lang.
+ * String[])
+ */
+ public List<IParserNode> findPrimaryStatementInBody(final String[] primaryNames) {
+ return body == null ? null
+ : body.findPrimaryStatementsFromNameInChildren(primaryNames);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.nodes.IFunction#findPrimaryStatementsInBody(java.lang
+ * .String)
+ */
+ public List<IParserNode> findPrimaryStatementsInBody(final String primaryName) {
+ return body == null ? new ArrayList<IParserNode>()
+ : body.findPrimaryStatementsFromNameInChildren(new String[]
+ {primaryName});
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.IMetaDataListHolder#getAllMetaData()
+ */
+ public List<IMetaData> getAllMetaData() {
+ final List<IMetaData> list = new ArrayList<IMetaData>();
+
+ for (final Entry<MetaData, List<IMetaData>> entry : metaDataList.entrySet()) {
+ list.addAll(entry.getValue());
+ }
+
+ return list;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.IAsDocHolder#getAsDoc()
+ */
+ public IParserNode getAsDoc() {
+ return asDoc;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.IFunction#getBody()
+ */
+ public IParserNode getBody() {
+ return body;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.IFunction#getCyclomaticComplexity()
+ */
+ public int getCyclomaticComplexity() {
+ return cyclomaticComplexity;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.IFunction#getLocalVariables()
+ */
+ public Map<String, IParserNode> getLocalVariables() {
+ return localVariables;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.nodes.IMetaDataListHolder#getMetaData(com.adobe.ac.pmd
+ * .nodes.MetaData)
+ */
+ public List<IMetaData> getMetaData(final MetaData metaDataName) {
+ if (metaDataList.containsKey(metaDataName)) {
+ return metaDataList.get(metaDataName);
+ } else {
+ return new ArrayList<IMetaData>();
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.IMetaDataListHolder#getMetaDataCount()
+ */
+ public int getMetaDataCount() {
+ return metaDataList.size();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.ICommentHolder#getMultiLinesComment()
+ */
+ public List<IParserNode> getMultiLinesComment() {
+ return multiLinesComments;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.INamable#getName()
+ */
+ public String getName() {
+ return name.toString();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.IFunction#getParameters()
+ */
+ public List<IParameter> getParameters() {
+ return parameters;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.IFunction#getReturnType()
+ */
+ public IIdentifierNode getReturnType() {
+ return returnType;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.IFunction#getStatementNbInBody()
+ */
+ public int getStatementNbInBody() {
+ return 1 + getStatementInNode(body);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.IFunction#getSuperCall()
+ */
+ public IParserNode getSuperCall() {
+ if (body != null
+ && body.numChildren() != 0) {
+ for (final IParserNode childContent : body.getChildren()) {
+ if (NodeKind.CALL.equals(childContent.getId())
+ || NodeKind.DOT.equals(childContent.getId())) {
+ for (final IParserNode childCall : childContent.getChildren()) {
+ if (KeyWords.SUPER.toString().equals(childCall.getStringValue())) {
+ return childContent;
+ }
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.nodes.IModifiersHolder#is(com.adobe.ac.pmd.nodes.Modifier
+ * )
+ */
+ public boolean is(final Modifier modifier) // NOPMD
+ {
+ return modifiers.contains(modifier);
+ }
+
+ //@Override
+ public boolean isEventHandler() {
+ return getParameters().size() == 1
+ && getParameters().get(0).getType().toString().contains("Event");
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.IFunction#isGetter()
+ */
+ public boolean isGetter() {
+ return getInternalNode().is(NodeKind.GET);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.IFunction#isOverriden()
+ */
+ public boolean isOverriden() {
+ return is(Modifier.OVERRIDE);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.IVisible#isPublic()
+ */
+ public boolean isPublic() {
+ return is(Modifier.PUBLIC);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.IFunction#isSetter()
+ */
+ public boolean isSetter() {
+ return getInternalNode().is(NodeKind.SET);
+ }
+
+ private void computeCyclomaticComplexity() {
+ cyclomaticComplexity = 1 + body.computeCyclomaticComplexity();
+ }
+
+ private void computeFunctionContent(final IParserNode functionBodyNode) {
+ body = functionBodyNode;
+
+ computeCyclomaticComplexity();
+ if (body.numChildren() > 0) {
+ for (final IParserNode node : body.getChildren()) {
+ if (node.is(NodeKind.MULTI_LINE_COMMENT)) {
+ multiLinesComments.add(node);
+ }
+ }
+ }
+ computeVariableList(body);
+ }
+
+ private void computeParameterList(final IParserNode node) {
+ if (node.numChildren() != 0) {
+ for (final IParserNode parameterNode : node.getChildren()) {
+ parameters.add(FormalNode.create(parameterNode));
+ }
+ }
+ }
+
+ private void computeVariableList(final IParserNode node) {
+ if (node.is(NodeKind.VAR_LIST)) {
+ localVariables.put(node.getChild(0).getChild(0).getStringValue(),
+ node);
+ } else if (node.numChildren() > 0) {
+ for (final IParserNode child : node.getChildren()) {
+ computeVariableList(child);
+ }
+ }
+ }
+
+ private int getStatementInNode(final IParserNode node) {
+ int statementNb = 0;
+
+ if (node != null
+ && node.numChildren() != 0) {
+ int lastLine = node.getChild(0).getLine();
+ for (final IParserNode childContent : node.getChildren()) {
+ if (childContent.getLine() != lastLine) {
+ lastLine = childContent.getLine();
+ statementNb++;
+ }
+ statementNb += getStatementInNode(childContent);
+ }
+ }
+
+ return statementNb;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/impl/IdentifierNode.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/impl/IdentifierNode.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/impl/IdentifierNode.java
new file mode 100644
index 0000000..dbade76
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/impl/IdentifierNode.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 org.apache.flex.pmd.nodes.impl;
+
+import org.apache.flex.pmd.nodes.IIdentifierNode;
+import org.apache.flex.pmd.parser.IParserNode;
+
+/**
+ * @author xagnetti
+ */
+class IdentifierNode extends AbstractNode implements IIdentifierNode {
+ /**
+ * @param node
+ * @return
+ */
+ static IdentifierNode create(final IParserNode node) {
+ return new IdentifierNode(node).compute();
+ }
+
+ /**
+ * @param node
+ */
+ protected IdentifierNode(final IParserNode node) {
+ super(node);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.impl.AbstractNode#compute()
+ */
+ @Override
+ public IdentifierNode compute() {
+ return this;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return getInternalNode().getStringValue();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/impl/MetaDataNode.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/impl/MetaDataNode.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/impl/MetaDataNode.java
new file mode 100644
index 0000000..032be64
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/impl/MetaDataNode.java
@@ -0,0 +1,123 @@
+/*
+ * 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 org.apache.flex.pmd.nodes.impl;
+
+import org.apache.flex.pmd.nodes.IMetaData;
+import org.apache.flex.pmd.parser.IParserNode;
+
+import java.util.*;
+
+/**
+ * @author xagnetti
+ */
+class MetaDataNode extends AbstractNode implements IMetaData {
+ private List<String> attributeNames;
+ private String name;
+ private String parameter;
+ private Map<String, String[]> parameters;
+
+ /**
+ * @param node
+ */
+ protected MetaDataNode(final IParserNode node) {
+ super(node);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.impl.AbstractNode#compute()
+ */
+ @Override
+ public MetaDataNode compute() {
+ final String stringValue = getInternalNode().getStringValue();
+
+ name = stringValue.indexOf(" ( ") > -1 ? stringValue.substring(0,
+ stringValue.indexOf(" ( "))
+ : stringValue;
+ parameter = stringValue.indexOf("( ") > -1 ? stringValue.substring(stringValue.indexOf("( ") + 2,
+ stringValue.lastIndexOf(" )"))
+ : "";
+
+ computeAttributeNames();
+ return this;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.IMetaData#getAttributeNames()
+ */
+ public List<String> getAttributeNames() {
+ return attributeNames;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.IMetaData#getDefaultValue()
+ */
+ public String getDefaultValue() {
+ return parameter;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.INamable#getName()
+ */
+ public String getName() {
+ return name;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.IMetaData#getProperty(java.lang.String)
+ */
+ public String[] getProperty(final String property) {
+ return parameters.containsKey(property) ? parameters.get(property)
+ : new String[]
+ {};
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.IMetaData#getPropertyAsList(java.lang.String)
+ */
+ public List<String> getPropertyAsList(final String property) {
+ return Arrays.asList(getProperty(property));
+ }
+
+ private void computeAttributeNames() {
+ attributeNames = new ArrayList<String>();
+ parameters = new LinkedHashMap<String, String[]>();
+
+ final String[] pairs = getPairs();
+
+ for (final String pair : pairs) {
+ final String[] pairSplit = pair.split("=");
+
+ if (pairSplit.length == 2) {
+ attributeNames.add(pairSplit[0].trim());
+ parameters.put(pairSplit[0].trim(),
+ pairSplit[1].trim().replaceAll("\'",
+ "").replaceAll("\"",
+ "").split(","));
+ }
+ }
+ }
+
+ private String[] getPairs() {
+ return parameter.split(",");
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/impl/NodeFactory.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/impl/NodeFactory.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/impl/NodeFactory.java
new file mode 100644
index 0000000..66da63c
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/impl/NodeFactory.java
@@ -0,0 +1,45 @@
+/*
+ * 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 org.apache.flex.pmd.nodes.impl;
+
+import org.apache.flex.pmd.nodes.IMetaData;
+import org.apache.flex.pmd.nodes.IPackage;
+import org.apache.flex.pmd.parser.IParserNode;
+
+/**
+ * @author xagnetti
+ */
+public final class NodeFactory {
+ /**
+ * @param metadataNode
+ * @return
+ */
+ public static IMetaData createMetaData(final IParserNode metadataNode) {
+ return new MetaDataNode(metadataNode).compute();
+ }
+
+ /**
+ * @param packageNode
+ * @return
+ */
+ public static IPackage createPackage(final IParserNode packageNode) {
+ return new PackageNode(packageNode).compute();
+ }
+
+ private NodeFactory() {
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/impl/PackageNode.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/impl/PackageNode.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/impl/PackageNode.java
new file mode 100644
index 0000000..b081802
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/impl/PackageNode.java
@@ -0,0 +1,146 @@
+/*
+ * 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 org.apache.flex.pmd.nodes.impl;
+
+import org.apache.flex.pmd.nodes.IClass;
+import org.apache.flex.pmd.nodes.IFunction;
+import org.apache.flex.pmd.nodes.IPackage;
+import org.apache.flex.pmd.parser.IParserNode;
+import org.apache.flex.pmd.parser.NodeKind;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author xagnetti
+ */
+class PackageNode extends AbstractNode implements IPackage {
+ private IClass classNode;
+ private final List<IFunction> functions;
+ private final List<IParserNode> imports;
+ private String name;
+
+ /**
+ * @param node
+ */
+ protected PackageNode(final IParserNode node) {
+ super(node);
+
+ imports = new ArrayList<IParserNode>();
+ functions = new ArrayList<IFunction>();
+ classNode = null;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.impl.AbstractNode#compute()
+ */
+ @Override
+ public PackageNode compute() {
+ final IParserNode classWrapperNode = getClassNodeFromCompilationUnitNode(getInternalNode(),
+ 3);
+ final IParserNode firstChild = getInternalNode().getChild(0);
+
+ if (firstChild.numChildren() > 0
+ && firstChild.getChild(0).getStringValue() != null) {
+ name = firstChild.getChild(0).getStringValue();
+ } else {
+ name = "";
+ }
+ if (classWrapperNode != null) {
+ classNode = new ClassNode(classWrapperNode).compute();
+ }
+
+ if (firstChild.numChildren() > 1
+ && firstChild.getChild(1).numChildren() != 0) {
+ final List<IParserNode> children = firstChild.getChild(1).getChildren();
+
+ for (final IParserNode node : children) {
+ if (node.is(NodeKind.IMPORT)) {
+ imports.add(node);
+ }
+ }
+ }
+ return this;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.IPackage#getClassNode()
+ */
+ public IClass getClassNode() {
+ return classNode;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.IPackage#getFullyQualifiedClassName()
+ */
+ public String getFullyQualifiedClassName() {
+ if (!"".equals(name)) {
+ return name
+ + "." + classNode.getName();
+ }
+ return classNode == null ? ""
+ : classNode.getName();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.IPackage#getFunctions()
+ */
+ public List<IFunction> getFunctions() {
+ return functions;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.IPackage#getImports()
+ */
+ public List<IParserNode> getImports() {
+ return imports;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.INamable#getName()
+ */
+ public String getName() {
+ return name;
+ }
+
+ private IParserNode getClassNodeFromCompilationUnitNode(final IParserNode node,
+ final int depth) {
+ if (depth == 0
+ || node.numChildren() == 0) {
+ return null;
+ }
+ for (final IParserNode child : node.getChildren()) {
+ if (child.is(NodeKind.CLASS)
+ || child.is(NodeKind.INTERFACE)) {
+ return child;
+ }
+ final IParserNode localClassNode = getClassNodeFromCompilationUnitNode(child,
+ depth - 1);
+
+ if (localClassNode != null) {
+ return localClassNode;
+ }
+ }
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/impl/VariableNode.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/impl/VariableNode.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/impl/VariableNode.java
new file mode 100644
index 0000000..5324c3e
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/impl/VariableNode.java
@@ -0,0 +1,182 @@
+/*
+ * 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 org.apache.flex.pmd.nodes.impl;
+
+import org.apache.flex.pmd.nodes.*;
+import org.apache.flex.pmd.parser.IParserNode;
+import org.apache.flex.pmd.parser.NodeKind;
+
+import java.util.*;
+import java.util.Map.Entry;
+
+/**
+ * Node representing a variable (var i : int = 0) It contains the variable name,
+ * its type name, the list of modifiers, the list of metadata, and the
+ * initialization expression (if any).
+ *
+ * @author xagnetti
+ */
+class VariableNode extends AbstractNode implements IVariable, IModifiersHolder {
+ private IFieldInitialization initializationExpression;
+ private final Map<MetaData, List<IMetaData>> metaDataList;
+ private final Set<Modifier> modifiers;
+ private IdentifierNode name;
+ private IdentifierNode type;
+
+ /**
+ * @param rootNode
+ */
+ protected VariableNode(final IParserNode rootNode) {
+ super(rootNode);
+
+ metaDataList = new LinkedHashMap<MetaData, List<IMetaData>>();
+ modifiers = new HashSet<Modifier>();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.nodes.IMetaDataListHolder#add(com.adobe.ac.pmd.nodes.
+ * IMetaData)
+ */
+ public void add(final IMetaData metaData) {
+ final MetaData metaDataImpl = MetaData.create(metaData.getName());
+ if (!metaDataList.containsKey(metaDataImpl)) {
+ metaDataList.put(metaDataImpl,
+ new ArrayList<IMetaData>());
+ }
+ metaDataList.get(metaDataImpl).add(metaData);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.nodes.IModifiersHolder#add(com.adobe.ac.pmd.nodes.Modifier
+ * )
+ */
+ public void add(final Modifier modifier) {
+ modifiers.add(modifier);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.impl.AbstractNode#compute()
+ */
+ @Override
+ public VariableNode compute() {
+ if (getInternalNode().is(NodeKind.NAME_TYPE_INIT)) {
+ computeNameTypeInit(getInternalNode());
+ } else {
+ if (getInternalNode().numChildren() != 0) {
+ for (final IParserNode child : getInternalNode().getChildren()) {
+ if (child.is(NodeKind.NAME_TYPE_INIT)) {
+ computeNameTypeInit(child);
+ } else if (child.is(NodeKind.META_LIST)) {
+ computeMetaDataList(this,
+ child);
+ }
+ }
+ }
+ }
+ return this;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.IMetaDataListHolder#getAllMetaData()
+ */
+ public List<IMetaData> getAllMetaData() {
+ final List<IMetaData> list = new ArrayList<IMetaData>();
+
+ for (final Entry<MetaData, List<IMetaData>> entry : metaDataList.entrySet()) {
+ list.addAll(entry.getValue());
+ }
+
+ return list;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.IVariable#getInitializationExpression()
+ */
+ public IFieldInitialization getInitializationExpression() {
+ return initializationExpression;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.nodes.IMetaDataListHolder#getMetaData(com.adobe.ac.pmd
+ * .nodes.MetaData)
+ */
+ public List<IMetaData> getMetaData(final MetaData metaDataName) {
+ return metaDataList.get(metaDataName);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.IMetaDataListHolder#getMetaDataCount()
+ */
+ public int getMetaDataCount() {
+ return metaDataList.size();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.INamable#getName()
+ */
+ public String getName() {
+ return name == null ? ""
+ : name.toString();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.IVariable#getType()
+ */
+ public IIdentifierNode getType() {
+ return type;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.nodes.IModifiersHolder#is(com.adobe.ac.pmd.nodes.Modifier
+ * )
+ */
+ public boolean is(final Modifier modifier) // NOPMD
+ {
+ return modifiers.contains(modifier);
+ }
+
+ private void computeNameTypeInit(final IParserNode nameTypeInit) {
+ if (nameTypeInit.numChildren() != 0) {
+ for (final IParserNode child : nameTypeInit.getChildren()) {
+ if (child.is(NodeKind.NAME)) {
+ name = IdentifierNode.create(child);
+ } else if (child.is(NodeKind.TYPE)) {
+ type = IdentifierNode.create(child);
+ } else if (child.is(NodeKind.INIT)) {
+ initializationExpression = FieldInitializationNode.create(child);
+ } else {
+ LOGGER.warning("unknown node type "
+ + child.toString());
+ }
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/utils/AsDocUtils.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/utils/AsDocUtils.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/utils/AsDocUtils.java
new file mode 100644
index 0000000..2ae2a6d
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/utils/AsDocUtils.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 org.apache.flex.pmd.nodes.utils;
+
+import org.apache.flex.pmd.nodes.asdoc.impl.ClassAsDocNode;
+import org.apache.flex.pmd.nodes.asdoc.impl.FunctionAsDocNode;
+import org.apache.flex.pmd.nodes.asdoc.impl.ParameterAsDocNode;
+
+/**
+ * @author xagnetti
+ */
+public final class AsDocUtils {
+ /**
+ * @param doc
+ * @return
+ */
+ public static ClassAsDocNode computeClassDoc(final String doc) {
+ return new ClassAsDocNode(doc);
+ }
+
+ /**
+ * @param doc
+ * @return
+ */
+ public static FunctionAsDocNode computeFunctionDoc(final String doc) {
+ return new FunctionAsDocNode(doc);
+ }
+
+ /**
+ * @param nameToBeSet
+ * @param descriptionToBeSet
+ * @return
+ */
+ public static ParameterAsDocNode computeParameterDoc(final String nameToBeSet,
+ final String descriptionToBeSet) {
+ return new ParameterAsDocNode(nameToBeSet, descriptionToBeSet);
+ }
+
+ private AsDocUtils() {
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/utils/FunctionUtils.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/utils/FunctionUtils.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/utils/FunctionUtils.java
new file mode 100644
index 0000000..5b9283f
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/utils/FunctionUtils.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 org.apache.flex.pmd.nodes.utils;
+
+import org.apache.flex.pmd.files.IFlexFile;
+import org.apache.flex.pmd.files.impl.FileUtils;
+import org.apache.flex.pmd.parser.IParserNode;
+
+/**
+ * @author xagnetti
+ */
+public final class FunctionUtils {
+ /**
+ * @param currentFile
+ * @param block
+ * @return
+ */
+ public static int computeFunctionLength(final IFlexFile currentFile,
+ final IParserNode block) {
+ int lineNb = 1;
+ final int firstLine = block.getChild(0).getLine();
+ final int lastLine = block.getLastChild().getLine();
+
+ for (int lineIndex = firstLine; lineIndex < lastLine; lineIndex++) {
+ if (FileUtils.isLineACorrectStatement(currentFile.getLineAt(lineIndex))) {
+ lineNb++;
+ }
+ }
+ return lineNb;
+ }
+
+ private FunctionUtils() {
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/IFlexViolation.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/IFlexViolation.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/IFlexViolation.java
new file mode 100644
index 0000000..1335f8f
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/IFlexViolation.java
@@ -0,0 +1,52 @@
+/*
+ * 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 org.apache.flex.pmd.rules;
+
+import net.sourceforge.pmd.RuleViolation;
+import org.apache.flex.pmd.files.IFlexFile;
+
+public interface IFlexViolation extends Comparable<IFlexViolation>, RuleViolation {
+ /**
+ * @param messageToAppend
+ */
+ void appendToMessage(final String messageToAppend);
+
+ /**
+ * @return the rule message
+ */
+ String getRuleMessage();
+
+ /**
+ * @param replacement
+ * @param index
+ */
+ void replacePlaceholderInMessage(final String replacement,
+ final int index);
+
+ /**
+ * @param column
+ */
+ void setEndColumn(final int column);
+
+ /**
+ * @param violatedFile
+ * @param ruleSetName
+ * @return
+ */
+ String toXmlString(final IFlexFile violatedFile,
+ final String ruleSetName);
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/AbstractAstFlexRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/AbstractAstFlexRule.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/AbstractAstFlexRule.java
new file mode 100644
index 0000000..966c15b
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/AbstractAstFlexRule.java
@@ -0,0 +1,970 @@
+/*
+ * 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 org.apache.flex.pmd.rules.core;
+
+import org.apache.flex.pmd.nodes.*;
+import org.apache.flex.pmd.parser.IParserNode;
+import org.apache.flex.pmd.parser.NodeKind;
+import org.apache.flex.pmd.rules.IFlexViolation;
+import org.apache.flex.pmd.utils.StackTraceUtils;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.NoSuchElementException;
+import java.util.logging.Logger;
+
+/**
+ * Abstract class for AST-based rule Extends this class if your rule is only
+ * detectable in an AS script block, which can be converted into an Abstract
+ * Syntax Tree. Then you will be able to either use the visitor pattern, or to
+ * iterate from the package node, in order to find your violation(s).
+ *
+ * @author xagnetti
+ */
+public abstract class AbstractAstFlexRule extends AbstractFlexRule implements IFlexAstRule {
+ /**
+ *
+ */
+ protected enum FunctionType {
+ GETTER, NORMAL, SETTER
+ }
+
+ /**
+ *
+ */
+ protected enum VariableOrConstant {
+ CONSTANT, VARIABLE
+ }
+
+ /**
+ *
+ */
+ protected enum VariableScope {
+ IN_CLASS, IN_FUNCTION
+ }
+
+ private interface ExpressionVisitor {
+ void visitExpression(final IParserNode ast);
+ }
+
+ private static final Logger LOGGER = Logger.getLogger(AbstractAstFlexRule.class.getName());
+
+ /**
+ * @param functionNode
+ * @return
+ */
+ /**
+ * @param functionNode
+ * @return
+ */
+ protected static IParserNode getNameFromFunctionDeclaration(final IParserNode functionNode) {
+ IParserNode nameChild = null;
+
+ for (final IParserNode child : functionNode.getChildren()) {
+ if (child.is(NodeKind.NAME)) {
+ nameChild = child;
+ break;
+ }
+ }
+ return nameChild;
+ }
+
+ /**
+ * @param fieldNode
+ * @return
+ */
+ protected static IParserNode getTypeFromFieldDeclaration(final IParserNode fieldNode) {
+ return fieldNode.getChild(0).getChild(1);
+ }
+
+ private final List<IFlexViolation> violations;
+
+ /**
+ *
+ */
+ public AbstractAstFlexRule() {
+ super();
+
+ violations = new ArrayList<IFlexViolation>();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractFlexRule#isConcernedByTheCurrentFile
+ * ()
+ */
+ @Override
+ public boolean isConcernedByTheCurrentFile() {
+ return true;
+ }
+
+ /**
+ * @param function
+ * @return the added violation positioned on the given function node
+ */
+ protected final IFlexViolation addViolation(final IFunction function) {
+ final IParserNode name = getNameFromFunctionDeclaration(function.getInternalNode());
+
+ return addViolation(name,
+ name,
+ name.getStringValue());
+ }
+
+ /**
+ * @param function
+ * @param messageToReplace
+ * @return
+ */
+ protected final IFlexViolation addViolation(final IFunction function,
+ final String messageToReplace) {
+ final IParserNode name = getNameFromFunctionDeclaration(function.getInternalNode());
+
+ return addViolation(name,
+ name,
+ messageToReplace);
+ }
+
+ /**
+ * @param violatingNode
+ * @return the added violation replacing the threshold value in the message
+ * if any.
+ */
+ protected final IFlexViolation addViolation(final INode violatingNode) {
+ return addViolation(violatingNode.getInternalNode(),
+ violatingNode.getInternalNode());
+ }
+
+ /**
+ * @param violatingNode
+ * @return the added violation replacing the threshold value in the message
+ * if any.
+ */
+ protected final IFlexViolation addViolation(final INode violatingNode,
+ final String... messageToReplace) {
+ return addViolation(violatingNode.getInternalNode(),
+ violatingNode.getInternalNode(),
+ messageToReplace);
+ }
+
+ /**
+ * @param violatingNode
+ * @return the added violation replacing the threshold value in the message
+ * if any.
+ */
+ protected final IFlexViolation addViolation(final IParserNode violatingNode) {
+ return addViolation(violatingNode,
+ violatingNode);
+ }
+
+ /**
+ * @param beginningNode
+ * @param endNode
+ * @param messageToReplace
+ * @return the add violation replacing the {0} token by the specified message
+ */
+ protected final IFlexViolation addViolation(final IParserNode beginningNode,
+ final IParserNode endNode,
+ final String... messageToReplace) {
+ if (isAlreadyViolationAdded(beginningNode)) {
+ return null;
+ }
+ final IFlexViolation violation = addViolation(ViolationPosition.create(beginningNode.getLine(),
+ endNode.getLine(),
+ beginningNode.getColumn(),
+ endNode.getColumn()));
+
+ for (int i = 0; i < messageToReplace.length; i++) {
+ violation.replacePlaceholderInMessage(messageToReplace[i],
+ i);
+ }
+
+ return violation;
+ }
+
+ /**
+ * @param violatingNode
+ * @param messageToReplace
+ * @return the add violation replacing the {0} token by the specified message
+ */
+ protected final IFlexViolation addViolation(final IParserNode violatingNode,
+ final String... messageToReplace) {
+ return addViolation(violatingNode,
+ violatingNode,
+ messageToReplace);
+ }
+
+ /**
+ * @param violationPosition
+ * @return the added violation positioned at the given position
+ */
+ protected final IFlexViolation addViolation(final ViolationPosition violationPosition) {
+ return addViolation(violations,
+ violationPosition);
+ }
+
+ /**
+ * find the violations list from the given class node
+ *
+ * @param classNode
+ */
+ protected void findViolations(final IClass classNode) {
+ findViolationsFromAttributes(classNode.getAttributes());
+ findViolationsFromConstants(classNode.getConstants());
+ findViolations(classNode.getFunctions());
+ if (classNode.getConstructor() != null) {
+ findViolationsFromConstructor(classNode.getConstructor());
+ }
+ }
+
+ /**
+ * find violations in every function in a class
+ *
+ * @param function
+ */
+ protected void findViolations(final IFunction function) {
+ }
+
+ /**
+ * Override this method if you need to find violations from the package ( or
+ * any subsequent node like class or function)
+ *
+ * @param packageNode
+ */
+ protected void findViolations(final IPackage packageNode) {
+ final IClass classNode = packageNode.getClassNode();
+
+ if (classNode != null) {
+ findViolations(classNode);
+ }
+ }
+
+ /**
+ * find the violations list from the given functions list
+ *
+ * @param functions
+ */
+ protected void findViolations(final List<IFunction> functions) {
+ for (final IFunction function : functions) {
+ findViolations(function);
+ }
+ }
+
+ /**
+ * find the violations list from the given class variables list
+ *
+ * @param variables
+ */
+ protected void findViolationsFromAttributes(final List<IAttribute> variables) {
+ }
+
+ /**
+ * find the violations list from the given class constants list
+ *
+ * @param constants
+ */
+ protected void findViolationsFromConstants(final List<IConstant> constants) {
+ }
+
+ /**
+ * find the violations list from the given class constructor node
+ *
+ * @param constructor
+ */
+ protected void findViolationsFromConstructor(final IFunction constructor) {
+ }
+
+ /**
+ * Find violations in the current file
+ */
+ @Override
+ protected final List<IFlexViolation> findViolationsInCurrentFile() {
+ try {
+ if (getCurrentPackageNode() != null) {
+ visitCompilationUnit(getCurrentPackageNode().getInternalNode());
+ findViolations(getCurrentPackageNode());
+ }
+ } catch (final Exception e) {
+ LOGGER.warning("on "
+ + getCurrentFile().getFilePath());
+ LOGGER.warning(StackTraceUtils.print(e));
+ }
+ final List<IFlexViolation> copy = new ArrayList<IFlexViolation>(violations);
+
+ violations.clear();
+
+ return copy;
+ }
+
+ /**
+ * @param statementNode
+ */
+ protected void visitAs(final IParserNode statementNode) {
+ }
+
+ /**
+ * @param catchNode
+ */
+ protected void visitCatch(final IParserNode catchNode) {
+ visitNameTypeInit(catchNode.getChild(0));
+ visitBlock(catchNode.getChild(1));
+ }
+
+ /**
+ * @param classNode
+ */
+ protected void visitClass(final IParserNode classNode) {
+ IParserNode content = null;
+ for (final IParserNode node : classNode.getChildren()) {
+ if (node.is(NodeKind.CONTENT)) {
+ content = node;
+ break;
+ }
+ }
+ visitClassContent(content);
+ }
+
+ /**
+ * Visit the condition of a if, while, ...
+ *
+ * @param condition
+ */
+ protected void visitCondition(final IParserNode condition) {
+ visitExpression(condition);
+ }
+
+ /**
+ * @param doNode
+ */
+ protected void visitDo(final IParserNode doNode) {
+ visitBlock(doNode.getChild(0));
+ visitCondition(doNode.getChild(1));
+ }
+
+ /**
+ * @param ifNode
+ */
+ protected void visitElse(final IParserNode ifNode) {
+ visitBlock(ifNode.getChild(2));
+ }
+
+ /**
+ * Visit empty statement
+ *
+ * @param statementNode
+ */
+ protected void visitEmptyStatetement(final IParserNode statementNode) {
+ }
+
+ /**
+ * @param finallyNode
+ */
+ protected void visitFinally(final IParserNode finallyNode) {
+ if (isNodeNavigable(finallyNode)) {
+ visitBlock(finallyNode.getChild(0));
+ }
+ }
+
+ /**
+ * @param forNode
+ */
+ protected void visitFor(final IParserNode forNode) {
+ visitBlock(forNode.getChild(3));
+ }
+
+ /**
+ * @param foreachNode
+ */
+ protected void visitForEach(final IParserNode foreachNode) {
+ visitBlock(foreachNode.getChild(2));
+ }
+
+ /**
+ * @param functionNode
+ * @param type
+ */
+ protected void visitFunction(final IParserNode functionNode,
+ final FunctionType type) {
+ final Iterator<IParserNode> iterator = functionNode.getChildren().iterator();
+ IParserNode currentNode = iterator.next();
+
+ while (currentNode.is(NodeKind.META_LIST)
+ || currentNode.is(NodeKind.MOD_LIST) || currentNode.is(NodeKind.AS_DOC)
+ || currentNode.is(NodeKind.MULTI_LINE_COMMENT)) {
+ currentNode = iterator.next();
+ }
+ currentNode = iterator.next();
+ visitParameters(currentNode);
+ currentNode = iterator.next();
+ visitFunctionReturnType(currentNode);
+ try {
+ // Intrinsic functions in AS2
+ currentNode = iterator.next();
+ visitFunctionBody(currentNode);
+ } catch (final NoSuchElementException e) {
+ }
+ }
+
+ /**
+ * @param functionReturnTypeNode
+ */
+ protected void visitFunctionReturnType(final IParserNode functionReturnTypeNode) {
+ visitBlock(functionReturnTypeNode);
+ }
+
+ /**
+ * @param ifNode
+ */
+ protected void visitIf(final IParserNode ifNode) {
+ visitCondition(ifNode.getChild(0));
+ visitThen(ifNode);
+ if (ifNode.numChildren() == 3) {
+ visitElse(ifNode);
+ }
+ }
+
+ /**
+ * @param interfaceNode
+ */
+ protected void visitInterface(final IParserNode interfaceNode) {
+ }
+
+ /**
+ * @param methodCallNode
+ */
+ protected void visitMethodCall(final IParserNode methodCallNode) {
+ final Iterator<IParserNode> iterator = methodCallNode.getChildren().iterator();
+ visitExpression(iterator.next());
+ do {
+ visitExpressionList(iterator.next());
+ }
+ while (iterator.hasNext());
+ }
+
+ /**
+ * @param newExpression
+ */
+ protected void visitNewExpression(final IParserNode newExpression) {
+ visitExpression(newExpression.getChild(0));
+ visitExpressionList(newExpression.getChild(1));
+ }
+
+ protected void visitOperator(final IParserNode statementNode) {
+ }
+
+ /**
+ * @param functionParametersNode
+ */
+ protected void visitParameters(final IParserNode functionParametersNode) {
+ if (isNodeNavigable(functionParametersNode)) {
+ for (final IParserNode node2 : functionParametersNode.getChildren()) {
+ visitNameTypeInit(node2.getChild(0));
+ }
+ }
+ }
+
+ protected void visitRelationalExpression(final IParserNode ast) {
+ visitExpression(ast,
+ NodeKind.RELATION,
+ new ExpressionVisitor() {
+ public void visitExpression(final IParserNode ast) {
+ visitShiftExpression(ast);
+ }
+ });
+ }
+
+ /**
+ * @param ast
+ */
+ protected void visitReturn(final IParserNode ast) {
+ if (isNodeNavigable(ast)) {
+ visitExpression(ast.getChild(0));
+ }
+ }
+
+ /**
+ * @param statementNode
+ */
+ protected void visitStatement(final IParserNode statementNode) {
+ switch (statementNode.getId()) {
+ case OP:
+ visitOperator(statementNode);
+ break;
+ case AS:
+ visitAs(statementNode);
+ break;
+ case RETURN:
+ visitReturn(statementNode);
+ break;
+ case IF:
+ visitIf(statementNode);
+ break;
+ case FOR:
+ visitFor(statementNode);
+ break;
+ case FOREACH:
+ visitForEach(statementNode);
+ break;
+ case DO:
+ visitDo(statementNode);
+ break;
+ case WHILE:
+ visitWhile(statementNode);
+ break;
+ case SWITCH:
+ visitSwitch(statementNode);
+ break;
+ case TRY:
+ visitTry(statementNode);
+ break;
+ case CATCH:
+ visitCatch(statementNode);
+ break;
+ case FINALLY:
+ visitFinally(statementNode);
+ break;
+ case STMT_EMPTY:
+ visitEmptyStatetement(statementNode);
+ break;
+ case LEFT_CURLY_BRACKET:
+ visitBlock(statementNode);
+ break;
+ default:
+ visitExpressionList(statementNode);
+ }
+ }
+
+ /**
+ * @param switchNode
+ */
+ protected void visitSwitch(final IParserNode switchNode) {
+ final Iterator<IParserNode> iterator = switchNode.getChildren().iterator();
+
+ visitExpression(iterator.next());
+
+ final IParserNode cases = iterator.next();
+
+ for (final IParserNode caseNode : cases.getChildren()) {
+ final IParserNode child = caseNode.getChild(0);
+
+ if (child.is(NodeKind.DEFAULT)) {
+ visitSwitchDefaultCase(caseNode.getChild(1));
+ } else {
+ visitSwitchCase(caseNode.getChild(1));
+ visitExpression(child);
+ }
+ }
+ }
+
+ /**
+ * @param switchCaseNode
+ */
+ protected void visitSwitchCase(final IParserNode switchCaseNode) {
+ visitBlock(switchCaseNode);
+ }
+
+ /**
+ * @param defaultCaseNode
+ */
+ protected void visitSwitchDefaultCase(final IParserNode defaultCaseNode) {
+ visitBlock(defaultCaseNode);
+ }
+
+ /**
+ * @param ifNode
+ */
+ protected void visitThen(final IParserNode ifNode) {
+ visitBlock(ifNode.getChild(1));
+ }
+
+ /**
+ * @param ast
+ */
+ protected void visitTry(final IParserNode ast) {
+ visitBlock(ast.getChild(0));
+ }
+
+ /**
+ * @param node
+ */
+ protected void visitVariableInitialization(final IParserNode node) {
+ visitExpression(node);
+ }
+
+ /**
+ * @param variableNode
+ * @param varOrConst
+ * @param scope
+ */
+ protected void visitVarOrConstList(final IParserNode variableNode,
+ final VariableOrConstant varOrConst,
+ final VariableScope scope) {
+ final Iterator<IParserNode> iterator = variableNode.getChildren().iterator();
+
+ IParserNode node = iterator.next();
+ while (node.is(NodeKind.META_LIST)
+ || node.is(NodeKind.MOD_LIST)) {
+ node = iterator.next();
+ }
+ while (node != null) {
+ visitNameTypeInit(node);
+ node = iterator.hasNext() ? iterator.next()
+ : null;
+ }
+ }
+
+ /**
+ * @param whileNode
+ */
+ protected void visitWhile(final IParserNode whileNode) {
+ visitCondition(whileNode.getChild(0));
+ visitBlock(whileNode.getChild(1));
+ }
+
+ private boolean isAlreadyViolationAdded(final IParserNode nodeToBeAdded) {
+ for (final IFlexViolation violation : violations) {
+ if (violation.getBeginLine() == nodeToBeAdded.getLine()
+ && violation.getBeginColumn() == nodeToBeAdded.getColumn()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private boolean isNodeNavigable(final IParserNode node) {
+ return node != null
+ && node.numChildren() != 0;
+ }
+
+ private void visitAdditiveExpression(final IParserNode ast) {
+ visitExpression(ast,
+ NodeKind.ADD,
+ new ExpressionVisitor() {
+ public void visitExpression(final IParserNode ast) {
+ visitMultiplicativeExpression(ast);
+ }
+ });
+ }
+
+ private void visitAndExpression(final IParserNode ast) {
+ visitExpression(ast,
+ NodeKind.AND,
+ new ExpressionVisitor() {
+ public void visitExpression(final IParserNode ast) {
+ visitBitwiseOrExpression(ast);
+ }
+ });
+ }
+
+ private void visitArrayAccessor(final IParserNode ast) {
+ final Iterator<IParserNode> iterator = ast.getChildren().iterator();
+ visitExpression(iterator.next());
+ do {
+ visitExpression(iterator.next());
+ }
+ while (iterator.hasNext());
+ }
+
+ private void visitBitwiseAndExpression(final IParserNode ast) {
+ visitExpression(ast,
+ NodeKind.B_AND,
+ new ExpressionVisitor() {
+ public void visitExpression(final IParserNode ast) {
+ visitEqualityExpression(ast);
+ }
+ });
+ }
+
+ private void visitBitwiseOrExpression(final IParserNode ast) {
+ visitExpression(ast,
+ NodeKind.B_OR,
+ new ExpressionVisitor() {
+ public void visitExpression(final IParserNode ast) {
+ visitBitwiseXorExpression(ast);
+ }
+ });
+ }
+
+ private void visitBitwiseXorExpression(final IParserNode ast) {
+ visitExpression(ast,
+ NodeKind.B_XOR,
+ new ExpressionVisitor() {
+ public void visitExpression(final IParserNode ast) {
+ visitBitwiseAndExpression(ast);
+ }
+ });
+ }
+
+ private void visitBlock(final IParserNode ast) {
+ if (isNodeNavigable(ast)) {
+ for (final IParserNode node : ast.getChildren()) {
+ visitStatement(node);
+ }
+ } else if (ast != null) {
+ visitStatement(ast);
+ }
+ }
+
+ private void visitClassContent(final IParserNode ast) {
+ if (isNodeNavigable(ast)) {
+ for (final IParserNode node : ast.getChildren()) {
+ if (node.is(NodeKind.VAR_LIST)) {
+ visitVarOrConstList(node,
+ VariableOrConstant.VARIABLE,
+ VariableScope.IN_CLASS);
+ } else if (node.is(NodeKind.CONST_LIST)) {
+ visitVarOrConstList(node,
+ VariableOrConstant.CONSTANT,
+ VariableScope.IN_CLASS);
+ }
+ }
+ for (final IParserNode node : ast.getChildren()) {
+ if (node.is(NodeKind.FUNCTION)) {
+ visitFunction(node,
+ FunctionType.NORMAL);
+ } else if (node.is(NodeKind.SET)) {
+ visitFunction(node,
+ FunctionType.SETTER);
+ } else if (node.is(NodeKind.GET)) {
+ visitFunction(node,
+ FunctionType.GETTER);
+ }
+ }
+ }
+ }
+
+ private void visitCompilationUnit(final IParserNode ast) {
+ for (final IParserNode node : ast.getChildren()) {
+ if (node.is(NodeKind.PACKAGE)
+ && node.numChildren() >= 2) {
+ visitPackageContent(node.getChild(1));
+ }
+ if (!node.is(NodeKind.PACKAGE)
+ && node.numChildren() > 0) {
+ visitPackageContent(node);
+ }
+ }
+ }
+
+ private void visitConditionalExpression(final IParserNode ast) {
+ if (ast != null) {
+ if (ast.is(NodeKind.CONDITIONAL)) {
+ final Iterator<IParserNode> iterator = ast.getChildren().iterator();
+ final IParserNode node = iterator.next();
+
+ visitOrExpression(node);
+
+ while (iterator.hasNext()) {
+ visitExpression(iterator.next());
+ visitExpression(iterator.next());
+ }
+ } else {
+ visitOrExpression(ast);
+ }
+ }
+ }
+
+ private void visitEqualityExpression(final IParserNode ast) {
+ visitExpression(ast,
+ NodeKind.EQUALITY,
+ new ExpressionVisitor() {
+ public void visitExpression(final IParserNode ast) {
+ visitRelationalExpression(ast);
+ }
+ });
+ }
+
+ private void visitExpression(final IParserNode ast) {
+ visitExpression(ast,
+ NodeKind.ASSIGN,
+ new ExpressionVisitor() {
+ public void visitExpression(final IParserNode ast) {
+ visitConditionalExpression(ast);
+ }
+ });
+ }
+
+ private void visitExpression(final IParserNode ast,
+ final NodeKind kind,
+ final ExpressionVisitor visitor) {
+ if (ast.is(kind)) {
+ final Iterator<IParserNode> iterator = ast.getChildren().iterator();
+ final IParserNode node = iterator.next();
+
+ visitor.visitExpression(node);
+
+ while (iterator.hasNext()) {
+ iterator.next();
+ visitor.visitExpression(iterator.next());
+ }
+ } else {
+ visitor.visitExpression(ast);
+ }
+ }
+
+ private void visitExpressionList(final IParserNode ast) {
+ if (isNodeNavigable(ast)) {
+ for (final IParserNode node : ast.getChildren()) {
+ visitExpression(node);
+ }
+ }
+ }
+
+ private void visitFunctionBody(final IParserNode node) {
+ visitBlock(node);
+ }
+
+ private void visitMultiplicativeExpression(final IParserNode ast) {
+ visitExpression(ast,
+ NodeKind.MULTIPLICATION,
+ new ExpressionVisitor() {
+ public void visitExpression(final IParserNode ast) {
+ visitUnaryExpression(ast);
+ }
+ });
+ }
+
+ private void visitNameTypeInit(final IParserNode ast) {
+ if (ast != null
+ && ast.numChildren() != 0) {
+ final Iterator<IParserNode> iterator = ast.getChildren().iterator();
+ IParserNode node;
+
+ iterator.next();
+ iterator.next();
+
+ if (iterator.hasNext()) {
+ node = iterator.next();
+ visitVariableInitialization(node);
+ }
+ }
+ }
+
+ private void visitObjectInitialization(final IParserNode ast) {
+ if (isNodeNavigable(ast)) {
+ for (final IParserNode node : ast.getChildren()) {
+ visitExpression(node.getChild(1));
+ }
+ }
+ }
+
+ private void visitOrExpression(final IParserNode ast) {
+ visitExpression(ast,
+ NodeKind.OR,
+ new ExpressionVisitor() {
+ public void visitExpression(final IParserNode ast) {
+ visitAndExpression(ast);
+ }
+ });
+ }
+
+ private void visitPackageContent(final IParserNode ast) {
+ if (isNodeNavigable(ast)) {
+ for (final IParserNode node : ast.getChildren()) {
+ if (node.is(NodeKind.CLASS)) {
+ visitClass(node);
+ } else if (node.is(NodeKind.INTERFACE)) {
+ visitInterface(node);
+ }
+ }
+ }
+ }
+
+ private void visitPrimaryExpression(final IParserNode ast) {
+ if (ast.is(NodeKind.NEW)) {
+ visitNewExpression(ast);
+ } else if (ast.numChildren() != 0
+ && ast.is(NodeKind.ARRAY)) {
+ visitExpressionList(ast);
+ } else if (ast.is(NodeKind.OBJECT)) {
+ visitObjectInitialization(ast);
+ } else if (ast.is(NodeKind.E4X_ATTR)) {
+ final IParserNode node = ast.getChild(0);
+
+ if (!node.is(NodeKind.NAME)
+ && !node.is(NodeKind.STAR)) {
+ visitExpression(node);
+ }
+ } else {
+ visitExpressionList(ast);
+ }
+ }
+
+ private void visitShiftExpression(final IParserNode ast) {
+ visitExpression(ast,
+ NodeKind.SHIFT,
+ new ExpressionVisitor() {
+ public void visitExpression(final IParserNode ast) {
+ visitAdditiveExpression(ast);
+ }
+ });
+ }
+
+ private void visitUnaryExpression(final IParserNode ast) {
+ switch (ast.getId()) {
+ case PRE_INC:
+ case PRE_DEC:
+ case MINUS:
+ case PLUS:
+ visitUnaryExpression(ast.getChild(0));
+ break;
+ default:
+ visitUnaryExpressionNotPlusMinus(ast);
+ }
+ }
+
+ private void visitUnaryExpressionNotPlusMinus(final IParserNode ast) {
+ switch (ast.getId()) {
+ case DELETE:
+ case VOID:
+ case TYPEOF:
+ case NOT:
+ case B_NOT:
+ visitExpression(ast.getChild(0));
+ break;
+ default:
+ visitUnaryPostfixExpression(ast);
+ }
+ }
+
+ private void visitUnaryPostfixExpression(final IParserNode ast) {
+ switch (ast.getId()) {
+ case ARRAY_ACCESSOR:
+ visitArrayAccessor(ast);
+ break;
+ case DOT:
+ case E4X_FILTER:
+ visitExpression(ast.getChild(0));
+ visitExpression(ast.getChild(1));
+ break;
+ case POST_INC:
+ case POST_DEC:
+ visitPrimaryExpression(ast.getChild(0));
+ break;
+ case CALL:
+ visitMethodCall(ast);
+ break;
+ case E4X_STAR:
+ visitExpression(ast.getChild(0));
+ break;
+ default:
+ visitPrimaryExpression(ast);
+ break;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/AbstractFlexMetaDataRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/AbstractFlexMetaDataRule.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/AbstractFlexMetaDataRule.java
new file mode 100644
index 0000000..e748078
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/AbstractFlexMetaDataRule.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 org.apache.flex.pmd.rules.core;
+
+import org.apache.flex.pmd.nodes.IAttribute;
+import org.apache.flex.pmd.nodes.IClass;
+import org.apache.flex.pmd.nodes.IFunction;
+import org.apache.flex.pmd.nodes.IMetaDataListHolder;
+
+import java.util.List;
+
+/**
+ * @author xagnetti
+ */
+public abstract class AbstractFlexMetaDataRule 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);
+
+ if (classNode.getMetaDataCount() > 0) {
+ findViolationsFromMetaDataList(classNode);
+ findViolationsFromClassMetaData(classNode);
+ }
+ }
+
+ /*
+ * (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.getMetaDataCount() > 0) {
+ findViolationsFromMetaDataList(function);
+ findViolationsFromFunctionMetaData(function);
+ }
+ }
+
+ /**
+ * @param attribute
+ */
+ protected void findViolationsFromAttributeMetaData(final IAttribute attribute) {
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#findViolationsFromAttributes
+ * (java.util.List)
+ */
+ @Override
+ protected final void findViolationsFromAttributes(final List<IAttribute> variables) {
+ for (final IAttribute attribute : variables) {
+ if (attribute.getMetaDataCount() > 0) {
+ findViolationsFromMetaDataList(attribute);
+ findViolationsFromAttributeMetaData(attribute);
+ }
+ }
+ }
+
+ /**
+ * @param classNode
+ */
+ protected void findViolationsFromClassMetaData(final IClass classNode) {
+ }
+
+ /**
+ * @param function
+ */
+ protected void findViolationsFromFunctionMetaData(final IFunction function) {
+ }
+
+ /**
+ * @param holder
+ */
+ protected void findViolationsFromMetaDataList(final IMetaDataListHolder holder) {
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/AbstractFlexRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/AbstractFlexRule.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/AbstractFlexRule.java
new file mode 100644
index 0000000..53adff5
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/AbstractFlexRule.java
@@ -0,0 +1,326 @@
+/*
+ * 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 org.apache.flex.pmd.rules.core;
+
+import net.sourceforge.pmd.PropertyDescriptor;
+import net.sourceforge.pmd.RuleContext;
+import net.sourceforge.pmd.RulePriority;
+import net.sourceforge.pmd.lang.ast.Node;
+import net.sourceforge.pmd.lang.rule.AbstractRule;
+import net.sourceforge.pmd.lang.rule.properties.IntegerProperty;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.flex.pmd.files.IFlexFile;
+import org.apache.flex.pmd.nodes.IPackage;
+import org.apache.flex.pmd.rules.IFlexViolation;
+import org.apache.flex.pmd.rules.core.thresholded.IThresholdedRule;
+import org.apache.flex.pmd.utils.RegexUtils;
+
+import java.util.*;
+import java.util.logging.Logger;
+import java.util.regex.Pattern;
+
+/**
+ * Abstract FlexPMD rule. Extends this class if you want to find violations at a
+ * very low level. Otherwise extends AbstractAstFlexRule, or
+ * AbstractRegexpBasedRule.
+ *
+ * @author xagnetti
+ */
+public abstract class AbstractFlexRule extends AbstractRule implements IFlexRule {
+ protected static final String MAXIMUM = "maximum";
+ protected static final String MINIMUM = "minimum";
+ private static final String AS3_COMMENT_TOKEN = "//";
+ private static final Logger LOGGER = Logger.getLogger(AbstractFlexRule.class.getName());
+ private static final String MXML_COMMENT_TOKEN = "<!--";
+ private IFlexFile currentFile;
+ private IPackage currentPackageNode;
+ private Set<String> excludes;
+ private Map<String, IFlexFile> filesInSourcePath;
+
+ /**
+ *
+ */
+ public AbstractFlexRule() {
+ super();
+
+ setDefaultPriority();
+ }
+
+ /**
+ * not used in FlexPMD
+ */
+ public final void apply(final List<? extends Node> astCompilationUnits,
+ final RuleContext ctx) {
+ }
+
+ /**
+ * @return Extracts the rulename from the qualified name of the underlying
+ * class
+ */
+ public final String getRuleName() {
+ final String qualifiedClassName = this.getClass().getName();
+ final String className = StringUtils.substringAfter(qualifiedClassName,
+ ".");
+
+ return className.replace("Rule",
+ "");
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.IFlexRule#processFile(com.adobe.ac.pmd.files
+ * .IFlexFile, com.adobe.ac.pmd.nodes.IPackage, java.util.Map)
+ */
+ public final List<IFlexViolation> processFile(final IFlexFile file,
+ final IPackage packageNode,
+ final Map<String, IFlexFile> files) {
+ List<IFlexViolation> violations = new ArrayList<IFlexViolation>();
+
+ currentFile = file;
+ filesInSourcePath = files;
+ currentPackageNode = packageNode;
+
+ if (isConcernedByTheCurrentFile()
+ && !isFileExcluded(file)) {
+ onRuleStart();
+ violations = findViolationsInCurrentFile();
+ }
+
+ return violations;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.rules.core.IFlexRule#setExcludes(java.util.Set)
+ */
+ public void setExcludes(final Set<String> excludesToBeSet) {
+ excludes = excludesToBeSet;
+ }
+
+ /**
+ * @param violatedLine
+ * @return
+ */
+ boolean isViolationIgnored(final String violatedLine) {
+ final boolean containsNoPmd = lineContainsNoPmd(violatedLine,
+ MXML_COMMENT_TOKEN)
+ || lineContainsNoPmd(violatedLine,
+ AS3_COMMENT_TOKEN);
+
+ if (!containsNoPmd) {
+ return false;
+ }
+ final String name = getRuleName().replaceAll("Rule",
+ "");
+ final String ruleName = name.contains(".") ? StringUtils.substringAfterLast(name,
+ ".")
+ : name;
+ final String strippedLine = computeStrippedLine(violatedLine);
+ return strippedLineContainsNoPmdAndRuleName(MXML_COMMENT_TOKEN,
+ ruleName,
+ strippedLine)
+ || strippedLineContainsNoPmdAndRuleName(AS3_COMMENT_TOKEN,
+ ruleName,
+ strippedLine);
+ }
+
+ /**
+ * @param violations
+ * @param position
+ * @return
+ */
+ protected final IFlexViolation addViolation(final List<IFlexViolation> violations,
+ final ViolationPosition position) {
+ final IFlexViolation violation = new Violation(position, this, getCurrentFile());
+ final int beginLine = position.getBeginLine();
+
+ prettyPrintMessage(violation);
+
+ if (beginLine == -1
+ || beginLine == 0) {
+ violations.add(violation);
+ } else if (beginLine <= getCurrentFile().getLinesNb()) {
+ if (isViolationIgnored(getCurrentFile().getLineAt(beginLine))) {
+ LOGGER.info(getRuleName()
+ + " has been ignored in " + getCurrentFile().getFilename() + " (" + beginLine + ")");
+ } else {
+ violations.add(violation);
+ }
+ }
+
+ return violation;
+ }
+
+ protected final IFlexViolation addViolation(final List<IFlexViolation> violations,
+ final ViolationPosition position,
+ final String... messageToReplace) {
+ final IFlexViolation violation = addViolation(violations,
+ position);
+
+ for (int i = 0; i < messageToReplace.length; i++) {
+ violation.replacePlaceholderInMessage(messageToReplace[i],
+ i);
+ }
+
+ return violation;
+ }
+
+ /**
+ * @return
+ */
+ protected abstract List<IFlexViolation> findViolationsInCurrentFile();
+
+ /**
+ * @return the current file under investigation
+ */
+ protected IFlexFile getCurrentFile() {
+ return currentFile;
+ }
+
+ /**
+ * @return
+ */
+ protected final IPackage getCurrentPackageNode() {
+ return currentPackageNode;
+ }
+
+ /**
+ * @return
+ */
+ protected abstract ViolationPriority getDefaultPriority();
+
+ /**
+ * @return
+ */
+ protected final Map<String, IFlexFile> getFilesInSourcePath() {
+ return filesInSourcePath;
+ }
+
+ /**
+ * @param rule
+ * @return
+ */
+ protected final Map<String, PropertyDescriptor> getThresholdedRuleProperties(final IThresholdedRule rule) {
+ final Map<String, PropertyDescriptor> properties = new LinkedHashMap<String, PropertyDescriptor>();
+
+ properties.put(rule.getThresholdName(),
+ new IntegerProperty(rule.getThresholdName(),
+ "",
+ Integer.MIN_VALUE,
+ Integer.MAX_VALUE,
+ rule.getDefaultThreshold(),
+ properties.size()));
+
+ return properties;
+ }
+
+ /**
+ * @return is this rule concerned by the current file
+ */
+ protected abstract boolean isConcernedByTheCurrentFile();
+
+ /**
+ * Called when the rule is started on the current file
+ */
+ protected void onRuleStart() {
+ }
+
+ private String computeStrippedLine(final String violatedLine) {
+ final String comment_token = getCurrentFile().isMxml() ? MXML_COMMENT_TOKEN
+ : AS3_COMMENT_TOKEN;
+ String strippedLine = violatedLine;
+
+ if (violatedLine.indexOf(comment_token
+ + " N") > 0) {
+ strippedLine = StringUtils.strip(violatedLine.substring(violatedLine.indexOf(comment_token
+ + " N")));
+ } else if (violatedLine.indexOf(comment_token
+ + "N") > 0) {
+ strippedLine = StringUtils.strip(violatedLine.substring(violatedLine.indexOf(comment_token
+ + "N")));
+ }
+ return strippedLine;
+ }
+
+ private boolean isFileExcluded(final IFlexFile file) {
+ if (excludes != null) {
+ for (final String exclusion : excludes) {
+ final Pattern pattern = Pattern.compile(exclusion);
+
+ if (RegexUtils.isMatch(pattern,
+ file.getFilePath())) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ private boolean lineContainsNoPmd(final String violatedLine,
+ final String comment_token) {
+ return violatedLine.contains(comment_token
+ + " No PMD")
+ || violatedLine.contains(comment_token
+ + " NO PMD") || violatedLine.contains(comment_token
+ + " NOPMD") || violatedLine.contains(comment_token
+ + "NOPMD");
+ }
+
+ private void prettyPrintMessage(final IFlexViolation violation) {
+ final int nbOfBraces = violation.getRuleMessage().split("\\{").length - 1;
+
+ if (this instanceof IThresholdedRule) {
+ final IThresholdedRule thresholdeRule = (IThresholdedRule) this;
+
+ violation.replacePlaceholderInMessage(String.valueOf(thresholdeRule.getThreshold()),
+ nbOfBraces - 2);
+ violation.replacePlaceholderInMessage(String.valueOf(thresholdeRule.getActualValueForTheCurrentViolation()),
+ nbOfBraces - 1);
+ }
+ if (getDescription() != null) {
+ violation.appendToMessage(". ");
+ violation.appendToMessage(getDescription());
+ }
+ }
+
+ private void setDefaultPriority() {
+ switch (getDefaultPriority()) {
+ case LOW:
+ setPriority(RulePriority.LOW);
+ break;
+ case NORMAL:
+ setPriority(RulePriority.MEDIUM);
+ break;
+ case HIGH:
+ setPriority(RulePriority.HIGH);
+ break;
+ }
+ }
+
+
+ private boolean strippedLineContainsNoPmdAndRuleName(final String comment_token,
+ final String ruleName,
+ final String strippedLine) {
+ return strippedLine.endsWith(comment_token
+ + " No PMD")
+ || strippedLine.endsWith(comment_token
+ + " NO PMD") || strippedLine.endsWith(comment_token
+ + " NOPMD") || strippedLine.endsWith(comment_token
+ + "NOPMD") || strippedLine.contains(ruleName);
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/AbstractForbiddenImportRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/AbstractForbiddenImportRule.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/AbstractForbiddenImportRule.java
new file mode 100644
index 0000000..fa4a304
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/AbstractForbiddenImportRule.java
@@ -0,0 +1,53 @@
+/*
+ * 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 org.apache.flex.pmd.rules.core;
+
+import org.apache.flex.pmd.nodes.IPackage;
+import org.apache.flex.pmd.parser.IParserNode;
+
+/**
+ * @author xagnetti
+ */
+public abstract class AbstractForbiddenImportRule extends AbstractAstFlexRule {
+
+ /**
+ *
+ */
+ public AbstractForbiddenImportRule() {
+ super();
+ }
+
+ /*
+ * (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) {
+ for (final IParserNode importNode : packageNode.getImports()) {
+ if (importNode.getStringValue().contains(getForbiddenImport())) {
+ addViolation(importNode);
+ }
+ }
+ }
+
+ /**
+ * @return
+ */
+ protected abstract String getForbiddenImport();
+}
\ No newline at end of file
[07/24] git commit: [flex-utilities]
[refs/heads/feature/pmd-5.2-language-module] - Initial commit of the PMD
language module for Apache Flex
Posted by cd...@apache.org.
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/parsley/RedundantMethodAttributeRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/parsley/RedundantMethodAttributeRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/parsley/RedundantMethodAttributeRuleTest.java
new file mode 100644
index 0000000..b775c4f
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/parsley/RedundantMethodAttributeRuleTest.java
@@ -0,0 +1,35 @@
+/*
+ * 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 org.apache.flex.pmd.rules.parsley;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class RedundantMethodAttributeRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("parsley.RedundantMethodAttribute.as", new ViolationPosition[]
+ {new ViolationPosition(29, 29)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new RedundantMethodAttributeRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/parsley/UnknownMetaDataAttributeRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/parsley/UnknownMetaDataAttributeRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/parsley/UnknownMetaDataAttributeRuleTest.java
new file mode 100644
index 0000000..76d4ad4
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/parsley/UnknownMetaDataAttributeRuleTest.java
@@ -0,0 +1,37 @@
+/*
+ * 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 org.apache.flex.pmd.rules.parsley;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class UnknownMetaDataAttributeRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("parsley.UnknownMetaDataAttribute.as", new ViolationPosition[]
+ {new ViolationPosition(24, 24),
+ new ViolationPosition(27, 27),
+ new ViolationPosition(21, 21)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new UnknownMetaDataAttributeRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/performance/AvoidDeclarationInLoopRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/performance/AvoidDeclarationInLoopRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/performance/AvoidDeclarationInLoopRuleTest.java
new file mode 100644
index 0000000..3cd2ae3
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/performance/AvoidDeclarationInLoopRuleTest.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 org.apache.flex.pmd.rules.performance;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class AvoidDeclarationInLoopRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("bug.FlexPMD181.as", new ViolationPosition[]
+ {new ViolationPosition(2326)}),
+ new ExpectedViolation("bug.FlexPMD88.as", new ViolationPosition[]
+ {new ViolationPosition(36)}),
+ new ExpectedViolation("com.adobe.ac.ncss.mxml.IterationsList.mxml",
+ new ViolationPosition[]
+ {new ViolationPosition(39),
+ new ViolationPosition(50),
+ new ViolationPosition(62)}),
+ new ExpectedViolation("com.adobe.ac.ncss.TestResult.as", new ViolationPosition[]
+ {new ViolationPosition(123),
+ new ViolationPosition(137)}),
+ new ExpectedViolation("Looping.as", new ViolationPosition[]
+ {new ViolationPosition(51)}),
+ new ExpectedViolation("PngEncoder.as", new ViolationPosition[]
+ {new ViolationPosition(188),
+ new ViolationPosition(207),
+ new ViolationPosition(323),
+ new ViolationPosition(324),
+ new ViolationPosition(325),
+ new ViolationPosition(326),
+ new ViolationPosition(327),
+ new ViolationPosition(328),
+ new ViolationPosition(329),
+ new ViolationPosition(330),
+ new ViolationPosition(333),
+ new ViolationPosition(334),
+ new ViolationPosition(335),
+ new ViolationPosition(336),
+ new ViolationPosition(341),
+ new ViolationPosition(351),
+ new ViolationPosition(352),
+ new ViolationPosition(353),
+ new ViolationPosition(354),
+ new ViolationPosition(356),
+ new ViolationPosition(357),
+ new ViolationPosition(370),
+ new ViolationPosition(371),
+ new ViolationPosition(372),
+ new ViolationPosition(373),
+ new ViolationPosition(374),
+ new ViolationPosition(375),
+ new ViolationPosition(376),
+ new ViolationPosition(377),
+ new ViolationPosition(380),
+ new ViolationPosition(381),
+ new ViolationPosition(382),
+ new ViolationPosition(383),
+ new ViolationPosition(388),
+ new ViolationPosition(398),
+ new ViolationPosition(399),
+ new ViolationPosition(400),
+ new ViolationPosition(401),
+ new ViolationPosition(403),
+ new ViolationPosition(404),
+ new ViolationPosition(575),
+ new ViolationPosition(578),
+ new ViolationPosition(580),
+ new ViolationPosition(600),
+ new ViolationPosition(601),
+ new ViolationPosition(602),
+ new ViolationPosition(603)}),
+ new ExpectedViolation("RadonDataGrid.as", new ViolationPosition[]
+ {new ViolationPosition(176)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new AvoidDeclarationInLoopRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/performance/AvoidInstanciationInLoopRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/performance/AvoidInstanciationInLoopRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/performance/AvoidInstanciationInLoopRuleTest.java
new file mode 100644
index 0000000..f7c853e
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/performance/AvoidInstanciationInLoopRuleTest.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 org.apache.flex.pmd.rules.performance;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class AvoidInstanciationInLoopRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("PngEncoder.as", new ViolationPosition[]
+ {new ViolationPosition(238),
+ new ViolationPosition(265),
+ new ViolationPosition(272)}),
+ new ExpectedViolation("Looping.as", new ViolationPosition[]
+ {new ViolationPosition(31),
+ new ViolationPosition(34),
+ new ViolationPosition(38),
+ new ViolationPosition(44),
+ new ViolationPosition(47),
+ new ViolationPosition(51),
+ new ViolationPosition(56),
+ new ViolationPosition(59),
+ new ViolationPosition(63)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new AvoidInstanciationInLoopRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/performance/AvoidUsingMathCeilRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/performance/AvoidUsingMathCeilRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/performance/AvoidUsingMathCeilRuleTest.java
new file mode 100644
index 0000000..99fd230
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/performance/AvoidUsingMathCeilRuleTest.java
@@ -0,0 +1,33 @@
+/*
+ * 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 org.apache.flex.pmd.rules.performance;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+
+public class AvoidUsingMathCeilRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new AvoidUsingMathCeilRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/performance/AvoidUsingMathFloorRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/performance/AvoidUsingMathFloorRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/performance/AvoidUsingMathFloorRuleTest.java
new file mode 100644
index 0000000..a8079ee
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/performance/AvoidUsingMathFloorRuleTest.java
@@ -0,0 +1,36 @@
+/*
+ * 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 org.apache.flex.pmd.rules.performance;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class AvoidUsingMathFloorRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("PngEncoder.as", new ViolationPosition[]
+ {new ViolationPosition(188),
+ new ViolationPosition(207)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new AvoidUsingMathFloorRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/performance/AvoidUsingMathRoundRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/performance/AvoidUsingMathRoundRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/performance/AvoidUsingMathRoundRuleTest.java
new file mode 100644
index 0000000..2afdf2c
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/performance/AvoidUsingMathRoundRuleTest.java
@@ -0,0 +1,35 @@
+/*
+ * 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 org.apache.flex.pmd.rules.performance;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class AvoidUsingMathRoundRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("PngEncoder.as", new ViolationPosition[]
+ {new ViolationPosition(417)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new AvoidUsingMathRoundRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/performance/BindableClassRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/performance/BindableClassRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/performance/BindableClassRuleTest.java
new file mode 100644
index 0000000..3601608
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/performance/BindableClassRuleTest.java
@@ -0,0 +1,39 @@
+/*
+ * 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 org.apache.flex.pmd.rules.performance;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+import org.testng.annotations.Test;
+
+@Test(enabled = false) // This test requires test-data that was not donated to Apache
+public class BindableClassRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("bug.FlexPMD60.as", new ViolationPosition[]
+ {new ViolationPosition(19)}),
+ new ExpectedViolation("cairngorm.BindableModelLocator.as", new ViolationPosition[]
+ {new ViolationPosition(32)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new BindableClassRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/performance/CreationPolicySetToAllRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/performance/CreationPolicySetToAllRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/performance/CreationPolicySetToAllRuleTest.java
new file mode 100644
index 0000000..9c5c6a5
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/performance/CreationPolicySetToAllRuleTest.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 org.apache.flex.pmd.rules.performance;
+
+import org.apache.flex.pmd.rules.AbstractRegExpBasedRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractRegexpBasedRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class CreationPolicySetToAllRuleTest extends AbstractRegExpBasedRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("Main.mxml", new ViolationPosition[]
+ {new ViolationPosition(22)})};
+ }
+
+ @Override
+ protected String[] getMatchableLines() {
+ return new String[]
+ {"creationPolicy = Policy.ALL",
+ " creationPolicy=\"all\""};
+ }
+
+ @Override
+ protected AbstractRegexpBasedRule getRegexpBasedRule() {
+ return new CreationPolicySetToAllRule();
+ }
+
+ @Override
+ protected String[] getUnmatchableLines() {
+ return new String[]
+ {"creationPolic="};
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/performance/CyclomaticComplexityRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/performance/CyclomaticComplexityRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/performance/CyclomaticComplexityRuleTest.java
new file mode 100644
index 0000000..4c1e957
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/performance/CyclomaticComplexityRuleTest.java
@@ -0,0 +1,42 @@
+/*
+ * 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 org.apache.flex.pmd.rules.performance;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class CyclomaticComplexityRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("bug.FlexPMD181.as", new ViolationPosition[]
+ {new ViolationPosition(2182),
+ new ViolationPosition(2280)}),
+ new ExpectedViolation("com.adobe.ac.ncss.LongSwitch.as", new ViolationPosition[]
+ {new ViolationPosition(27)}),
+ new ExpectedViolation("PngEncoder.as", new ViolationPosition[]
+ {new ViolationPosition(531)}),
+ new ExpectedViolation("RadonDataGrid.as", new ViolationPosition[]
+ {new ViolationPosition(148)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new CyclomaticComplexityRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/performance/DeeplyNestedIfRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/performance/DeeplyNestedIfRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/performance/DeeplyNestedIfRuleTest.java
new file mode 100644
index 0000000..84567a0
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/performance/DeeplyNestedIfRuleTest.java
@@ -0,0 +1,43 @@
+/*
+ * 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 org.apache.flex.pmd.rules.performance;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class DeeplyNestedIfRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("bug.Duane.mxml", new ViolationPosition[]
+ {new ViolationPosition(73),
+ new ViolationPosition(77),
+ new ViolationPosition(82)}),
+ new ExpectedViolation("com.adobe.ac.AbstractRowData.as", new ViolationPosition[]
+ {new ViolationPosition(47)}),
+ new ExpectedViolation("PngEncoder.as", new ViolationPosition[]
+ {new ViolationPosition(561),
+ new ViolationPosition(559),
+ new ViolationPosition(567)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new DeeplyNestedIfRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/performance/DynamicFiltersUsedInPopupTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/performance/DynamicFiltersUsedInPopupTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/performance/DynamicFiltersUsedInPopupTest.java
new file mode 100644
index 0000000..e7dcb20
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/performance/DynamicFiltersUsedInPopupTest.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 org.apache.flex.pmd.rules.performance;
+
+import org.apache.flex.pmd.rules.AbstractRegExpBasedRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractRegexpBasedRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class DynamicFiltersUsedInPopupTest extends AbstractRegExpBasedRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("filters.MyPopup.as", new ViolationPosition[]
+ {new ViolationPosition(25)}),
+ new ExpectedViolation("filters.MyPopup.mxml", new ViolationPosition[]
+ {new ViolationPosition(27),
+ new ViolationPosition(30)})};
+ }
+
+ @Override
+ protected String[] getMatchableLines() {
+ final String[] lines =
+ {"new DropShadowFilter",
+ "new GlowFilter",
+ "mx:DropShadowFilter"};
+ return lines;
+ }
+
+ @Override
+ protected AbstractRegexpBasedRule getRegexpBasedRule() {
+ return new DynamicFiltersUsedInPopup();
+ }
+
+ @Override
+ protected String[] getUnmatchableLines() {
+ final String[] lines =
+ {".filterFunction",
+ "DropShadowfilter("};
+ return lines;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/performance/HeavyConstructorRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/performance/HeavyConstructorRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/performance/HeavyConstructorRuleTest.java
new file mode 100644
index 0000000..701dd94
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/performance/HeavyConstructorRuleTest.java
@@ -0,0 +1,43 @@
+/*
+ * 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 org.apache.flex.pmd.rules.performance;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class HeavyConstructorRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("bug.FlexPMD88.as", new ViolationPosition[]
+ {new ViolationPosition(26)}),
+ new ExpectedViolation("flexunit.RaoulTest.as", new ViolationPosition[]
+ {new ViolationPosition(59)}),
+ new ExpectedViolation("PngEncoder.as", new ViolationPosition[]
+ {new ViolationPosition(113)}),
+ new ExpectedViolation("Looping.as", new ViolationPosition[]
+ {new ViolationPosition(27)}),
+ new ExpectedViolation("RadonDataGrid.as", new ViolationPosition[]
+ {new ViolationPosition(41)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new HeavyConstructorRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/performance/RecursiveStyleManagerRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/performance/RecursiveStyleManagerRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/performance/RecursiveStyleManagerRuleTest.java
new file mode 100644
index 0000000..cbb12f8
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/performance/RecursiveStyleManagerRuleTest.java
@@ -0,0 +1,36 @@
+/*
+ * 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 org.apache.flex.pmd.rules.performance;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class RecursiveStyleManagerRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("GoodComponent.as", new ViolationPosition[]
+ {new ViolationPosition(47),
+ new ViolationPosition(48)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new RecursiveStyleManagerRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/performance/UseTraceFunctionRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/performance/UseTraceFunctionRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/performance/UseTraceFunctionRuleTest.java
new file mode 100644
index 0000000..b8c3d3f
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/performance/UseTraceFunctionRuleTest.java
@@ -0,0 +1,40 @@
+/*
+ * 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 org.apache.flex.pmd.rules.performance;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class UseTraceFunctionRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("com.adobe.ac.ncss.LongSwitch.as", new ViolationPosition[]
+ {new ViolationPosition(113)}),
+ new ExpectedViolation("Simple.as", new ViolationPosition[]
+ {new ViolationPosition(1)}),
+ new ExpectedViolation("com.adobe.ac.ncss.BigImporterModel.as", new ViolationPosition[]
+ {new ViolationPosition(62),
+ new ViolationPosition(63)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new UseTraceFunctionRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/security/AllowAllSecureDomainRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/security/AllowAllSecureDomainRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/security/AllowAllSecureDomainRuleTest.java
new file mode 100644
index 0000000..ca5c6ae
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/security/AllowAllSecureDomainRuleTest.java
@@ -0,0 +1,77 @@
+/*
+ * 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 org.apache.flex.pmd.rules.security;
+
+import org.apache.flex.pmd.rules.AbstractRegExpBasedRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractRegexpBasedRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class AllowAllSecureDomainRuleTest extends AbstractRegExpBasedRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("bug.Security.as", new ViolationPosition[]
+ {new ViolationPosition(26)})};
+ }
+
+ @Override
+ protected String[] getMatchableLines() {
+ return new String[]
+ {"LocalConnection.allowDomain(\"*\")",
+ "LocalConnection.allowDomain( \"*\")",
+ "LocalConnection.allowDomain(\"*\" )",
+ "LocalConnection.allowDomain( \"*\" )",
+ "LocalConnection.allowDomain('*')",
+ "LocalConnection.allowDomain( '*')",
+ "LocalConnection.allowDomain('*' )",
+ "LocalConnection.allowDomain( '*' )",
+ "Security.allowDomain(\"*\")",
+ "Security.allowDomain( \"*\")",
+ "Security.allowDomain(\"*\" )",
+ "Security.allowDomain( \"*\" )",
+ "Security.allowDomain('*')",
+ "Security.allowDomain( '*')",
+ "Security.allowDomain('*' )",
+ "Security.allowDomain( '*' )"};
+ }
+
+ @Override
+ protected AbstractRegexpBasedRule getRegexpBasedRule() {
+ return new AllowAllSecureDomainRule();
+ }
+
+ @Override
+ protected String[] getUnmatchableLines() {
+ return new String[]
+ {"LocalConnection.allowDomain(\"www.google.com\")",
+ "LocalConnection.allowDomain( \"www.google.com\")",
+ "LocalConnection.allowDomain(\"www.google.com\" )",
+ "LocalConnection.allowDomain( \"www.google.com\" )",
+ "LocalConnection.allowDomain('www.google.com')",
+ "LocalConnection.allowDomain( 'www.google.com')",
+ "LocalConnection.allowDomain('www.google.com' )",
+ "LocalConnection.allowDomain( 'www.google.com' )",
+ "Security.allowDomain(\"www.google.com\")",
+ "Security.allowDomain( \"www.google.com\")",
+ "Security.allowDomain(\"www.google.com\" )",
+ "Security.allowDomain( \"www.google.com\" )",
+ "Security.allowDomain('www.google.com')",
+ "Security.allowDomain( 'www.google.com')",
+ "Security.allowDomain('www.google.com' )",
+ "Security.allowDomain( 'www.google.com' )"};
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/security/AllowInsecureDomainRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/security/AllowInsecureDomainRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/security/AllowInsecureDomainRuleTest.java
new file mode 100644
index 0000000..a9bb033
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/security/AllowInsecureDomainRuleTest.java
@@ -0,0 +1,50 @@
+/*
+ * 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 org.apache.flex.pmd.rules.security;
+
+import org.apache.flex.pmd.rules.AbstractRegExpBasedRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractRegexpBasedRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class AllowInsecureDomainRuleTest extends AbstractRegExpBasedRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("bug.Security.as", new ViolationPosition[]
+ {new ViolationPosition(27),
+ new ViolationPosition(28)})};
+ }
+
+ @Override
+ protected String[] getMatchableLines() {
+ return new String[]
+ {"LocalConnection.allowInsecureDomain(\"www.example.org\")",
+ "Security.allowInsecureDomain(\"www.example.org\");"};
+ }
+
+ @Override
+ protected AbstractRegexpBasedRule getRegexpBasedRule() {
+ return new AllowInsecureDomainRule();
+ }
+
+ @Override
+ protected String[] getUnmatchableLines() {
+ return new String[]
+ {"LocalConnection.allowDomain(\"www.example.org\")",
+ "Security.allowDomain(\"www.example.org\");"};
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/security/ImportLoadBestPracticeRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/security/ImportLoadBestPracticeRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/security/ImportLoadBestPracticeRuleTest.java
new file mode 100644
index 0000000..1b5decd
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/security/ImportLoadBestPracticeRuleTest.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 org.apache.flex.pmd.rules.security;
+
+import org.apache.flex.pmd.rules.AbstractRegExpBasedRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractRegexpBasedRule;
+
+public class ImportLoadBestPracticeRuleTest extends AbstractRegExpBasedRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {};
+ }
+
+ @Override
+ protected String[] getMatchableLines() {
+ return new String[]
+ {"SecurityDomain.currentDomain.loadBytes("};
+ }
+
+ @Override
+ protected AbstractRegexpBasedRule getRegexpBasedRule() {
+ return new ImportLoadBestPracticeRule();
+ }
+
+ @Override
+ protected String[] getUnmatchableLines() {
+ return new String[]
+ {"LocalConnection.allowDomain(\"www.example.org\")",
+ "Security.allowDomain(\"www.example.org\");",
+ "SecurityDomain.loadBytes"};
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/security/InsecureExactSettingsRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/security/InsecureExactSettingsRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/security/InsecureExactSettingsRuleTest.java
new file mode 100644
index 0000000..26325c6
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/security/InsecureExactSettingsRuleTest.java
@@ -0,0 +1,50 @@
+/*
+ * 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 org.apache.flex.pmd.rules.security;
+
+import org.apache.flex.pmd.rules.AbstractRegExpBasedRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractRegexpBasedRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class InsecureExactSettingsRuleTest extends AbstractRegExpBasedRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("bug.Security.as", new ViolationPosition[]
+ {new ViolationPosition(29)})};
+ }
+
+ @Override
+ protected String[] getMatchableLines() {
+ return new String[]
+ {"Security.exactSettings = true;",
+ "Security.exactSettings = false;"};
+ }
+
+ @Override
+ protected AbstractRegexpBasedRule getRegexpBasedRule() {
+ return new InsecureExactSettingsRule();
+ }
+
+ @Override
+ protected String[] getUnmatchableLines() {
+ return new String[]
+ {"LocalConnection.allowDomain(\"www.example.org\")",
+ "Security.allowDomain(\"www.example.org\");",
+ "SecurityDomain.loadBytes"};
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/security/LSOSecureFalseRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/security/LSOSecureFalseRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/security/LSOSecureFalseRuleTest.java
new file mode 100644
index 0000000..efc0bff
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/security/LSOSecureFalseRuleTest.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.flex.pmd.rules.security;
+
+import org.apache.flex.pmd.rules.AbstractRegExpBasedRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractRegexpBasedRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class LSOSecureFalseRuleTest extends AbstractRegExpBasedRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("bug.Security.as", new ViolationPosition[]
+ {new ViolationPosition(33)})};
+ }
+
+ @Override
+ protected String[] getMatchableLines() {
+ return new String[]
+ {" LSO.getLocal(name, null, true);",
+ " LSO.getLocal( name,null,true );",
+ " LSO.getLocal(name,null,true);",
+ " LSO.getLocal(name,null,true)",
+ " LSO.getLocal(name, null, false);"};
+ }
+
+ @Override
+ protected AbstractRegexpBasedRule getRegexpBasedRule() {
+ return new LSOSecureFalseRule();
+ }
+
+ @Override
+ protected String[] getUnmatchableLines() {
+ return new String[]
+ {"LocalConnection.allowDomain(\"www.example.org\")",
+ "Security.allowDomain(\"www.example.org\");",
+ "SecurityDomain.loadBytes",
+ "LocalConnection.allowDomain(\"www.example.org\");"};
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/security/LocalConnectionStarRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/security/LocalConnectionStarRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/security/LocalConnectionStarRuleTest.java
new file mode 100644
index 0000000..c09641e
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/security/LocalConnectionStarRuleTest.java
@@ -0,0 +1,52 @@
+/*
+ * 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 org.apache.flex.pmd.rules.security;
+
+import org.apache.flex.pmd.rules.AbstractRegExpBasedRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractRegexpBasedRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class LocalConnectionStarRuleTest extends AbstractRegExpBasedRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("bug.Security.as", new ViolationPosition[]
+ {new ViolationPosition(30)})};
+ }
+
+ @Override
+ protected String[] getMatchableLines() {
+ return new String[]
+ {" LocalConnection.allowDomain(\"*\");",
+ " LocalConnection.allowDomain( \"*\" );",
+ " LocalConnection.allowDomain('*');"};
+ }
+
+ @Override
+ protected AbstractRegexpBasedRule getRegexpBasedRule() {
+ return new LocalConnectionStarRule();
+ }
+
+ @Override
+ protected String[] getUnmatchableLines() {
+ return new String[]
+ {"LocalConnection.allowDomain(\"www.example.org\")",
+ "Security.allowDomain(\"www.example.org\");",
+ "SecurityDomain.loadBytes",
+ "LocalConnection.allowDomain(\"www.example.org\");"};
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/sizing/TooLongFunctionRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/sizing/TooLongFunctionRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/sizing/TooLongFunctionRuleTest.java
new file mode 100644
index 0000000..7f8804d
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/sizing/TooLongFunctionRuleTest.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 org.apache.flex.pmd.rules.sizing;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+import java.util.LinkedHashMap;
+
+public class TooLongFunctionRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ new LinkedHashMap<String, ViolationPosition[]>();
+
+ return new ExpectedViolation[]
+ {new ExpectedViolation("cairngorm.FatController.as", new ViolationPosition[]
+ {new ViolationPosition(85)}),
+ new ExpectedViolation("com.adobe.ac.ncss.NestedSwitch.as", new ViolationPosition[]
+ {new ViolationPosition(23)}),
+ new ExpectedViolation("com.adobe.ac.ncss.LongSwitch.as", new ViolationPosition[]
+ {new ViolationPosition(27)}),
+ new ExpectedViolation("ErrorToltipSkin.as", new ViolationPosition[]
+ {new ViolationPosition(144)}),
+ new ExpectedViolation("PngEncoder.as", new ViolationPosition[]
+ {new ViolationPosition(133),
+ new ViolationPosition(318),
+ new ViolationPosition(531)}),
+ new ExpectedViolation("RadonDataGrid.as", new ViolationPosition[]
+ {new ViolationPosition(72)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new TooLongFunctionRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/sizing/TooLongSwitchCaseRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/sizing/TooLongSwitchCaseRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/sizing/TooLongSwitchCaseRuleTest.java
new file mode 100644
index 0000000..cb923c3
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/sizing/TooLongSwitchCaseRuleTest.java
@@ -0,0 +1,44 @@
+/*
+ * 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 org.apache.flex.pmd.rules.sizing;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class TooLongSwitchCaseRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("ErrorToltipSkin.as", new ViolationPosition[]
+ {new ViolationPosition(177),
+ new ViolationPosition(202),
+ new ViolationPosition(240),
+ new ViolationPosition(278)}),
+ new ExpectedViolation("com.adobe.ac.ncss.NestedSwitch.as", new ViolationPosition[]
+ {new ViolationPosition(26),
+ new ViolationPosition(46)}),
+ new ExpectedViolation("com.adobe.ac.ncss.LongSwitch.as", new ViolationPosition[]
+ {new ViolationPosition(35),
+ new ViolationPosition(40)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new TooLongSwitchCaseRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/sizing/TooManyFieldInVORuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/sizing/TooManyFieldInVORuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/sizing/TooManyFieldInVORuleTest.java
new file mode 100644
index 0000000..9e54492
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/sizing/TooManyFieldInVORuleTest.java
@@ -0,0 +1,35 @@
+/*
+ * 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 org.apache.flex.pmd.rules.sizing;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class TooManyFieldInVORuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("com.adobe.ac.ncss.ArrayVO.as", new ViolationPosition[]
+ {new ViolationPosition(21)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new TooManyFieldInVORule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/sizing/TooManyFieldsRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/sizing/TooManyFieldsRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/sizing/TooManyFieldsRuleTest.java
new file mode 100644
index 0000000..bfbdfc9
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/sizing/TooManyFieldsRuleTest.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 org.apache.flex.pmd.rules.sizing;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class TooManyFieldsRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("com.adobe.ac.ncss.TestResult.as", new ViolationPosition[]
+ {new ViolationPosition(33)}),
+ new ExpectedViolation("Sorted.as", new ViolationPosition[]
+ {new ViolationPosition(25)}),
+ new ExpectedViolation("PngEncoder.as", new ViolationPosition[]
+ {new ViolationPosition(25)}),
+ new ExpectedViolation("com.adobe.ac.ncss.BigModel.as", new ViolationPosition[]
+ {new ViolationPosition(23)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new TooManyFieldsRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/sizing/TooManyFunctionRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/sizing/TooManyFunctionRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/sizing/TooManyFunctionRuleTest.java
new file mode 100644
index 0000000..c8ffedf
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/sizing/TooManyFunctionRuleTest.java
@@ -0,0 +1,39 @@
+/*
+ * 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 org.apache.flex.pmd.rules.sizing;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class TooManyFunctionRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("PngEncoder.as", new ViolationPosition[]
+ {new ViolationPosition(25)}),
+ new ExpectedViolation("com.adobe.ac.ncss.TestResult.as", new ViolationPosition[]
+ {new ViolationPosition(33)}),
+ new ExpectedViolation("com.adobe.ac.ncss.BigModel.as", new ViolationPosition[]
+ {new ViolationPosition(23)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new TooManyFunctionRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/sizing/TooManyParametersRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/sizing/TooManyParametersRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/sizing/TooManyParametersRuleTest.java
new file mode 100644
index 0000000..d8c2925
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/sizing/TooManyParametersRuleTest.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 org.apache.flex.pmd.rules.sizing;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class TooManyParametersRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("RadonDataGrid.as", new ViolationPosition[]
+ {new ViolationPosition(56),
+ new ViolationPosition(72),
+ new ViolationPosition(105)}),
+ new ExpectedViolation("PngEncoder.as", new ViolationPosition[]
+ {new ViolationPosition(531)}),
+ new ExpectedViolation("com.adobe.ac.ncss.BigImporterModel.as", new ViolationPosition[]
+ {new ViolationPosition(50)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new TooManyParametersRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/sizing/TooManyPublicRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/sizing/TooManyPublicRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/sizing/TooManyPublicRuleTest.java
new file mode 100644
index 0000000..4e6db08
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/sizing/TooManyPublicRuleTest.java
@@ -0,0 +1,39 @@
+/*
+ * 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 org.apache.flex.pmd.rules.sizing;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class TooManyPublicRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("com.adobe.ac.ncss.ArrayVO.as", new ViolationPosition[]
+ {new ViolationPosition(21)}),
+ new ExpectedViolation("com.adobe.ac.ncss.TestResult.as", new ViolationPosition[]
+ {new ViolationPosition(33)}),
+ new ExpectedViolation("com.adobe.ac.ncss.BigModel.as", new ViolationPosition[]
+ {new ViolationPosition(23)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new TooManyPublicRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/style/BadFormatLoggerRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/style/BadFormatLoggerRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/style/BadFormatLoggerRuleTest.java
new file mode 100644
index 0000000..bb66371
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/style/BadFormatLoggerRuleTest.java
@@ -0,0 +1,38 @@
+/*
+ * 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 org.apache.flex.pmd.rules.style;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class BadFormatLoggerRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("AbstractRowData.as", new ViolationPosition[]
+ {new ViolationPosition(32),
+ new ViolationPosition(33),
+ new ViolationPosition(34),
+ new ViolationPosition(35)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new BadFormatLoggerRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/style/ConstructorNonEmptyReturnTypeRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/style/ConstructorNonEmptyReturnTypeRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/style/ConstructorNonEmptyReturnTypeRuleTest.java
new file mode 100644
index 0000000..ba20008
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/style/ConstructorNonEmptyReturnTypeRuleTest.java
@@ -0,0 +1,35 @@
+/*
+ * 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 org.apache.flex.pmd.rules.style;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class ConstructorNonEmptyReturnTypeRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("com.adobe.ac.ncss.VoidConstructor.as", new ViolationPosition[]
+ {new ViolationPosition(25)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new ConstructorNonEmptyReturnTypeRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/style/CopyrightMissingRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/style/CopyrightMissingRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/style/CopyrightMissingRuleTest.java
new file mode 100644
index 0000000..308224e
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/style/CopyrightMissingRuleTest.java
@@ -0,0 +1,39 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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 org.apache.flex.pmd.rules.style;
+
+import org.apache.flex.pmd.rules.AbstractFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class CopyrightMissingRuleTest extends AbstractFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("Simple.as", new ViolationPosition[]
+ {new ViolationPosition(-1)}),
+ new ExpectedViolation("MainWithNoCopyright.mxml", new ViolationPosition[]
+ {new ViolationPosition(-1)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new CopyrightMissingRule();
+ }
+}
[10/24] git commit: [flex-utilities]
[refs/heads/feature/pmd-5.2-language-module] - Initial commit of the PMD
language module for Apache Flex
Posted by cd...@apache.org.
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/parsley.xml
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/parsley.xml b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/parsley.xml
new file mode 100644
index 0000000..1afd3c9
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/parsley.xml
@@ -0,0 +1,147 @@
+<?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="Parsley Rules"
+ xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd"
+ xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
+
+ <description>
+ The Parsley Ruleset contains a collection of good practices related to Parsley.
+ </description>
+
+ <rule
+ class="com.adobe.ac.pmd.rules.parsley.InaccessibleMetaDataRule"
+ message="Parsley metadata should not be placed on inaccessible members.">
+ <description>Parsley can only process metadata that is placed onto public members.</description>
+ <priority>1</priority>
+ <example>
+[MessageHandler]
+private function doSomething() : void // VIOLATION
+{
+}
+ </example>
+ </rule>
+
+ <rule
+ class="com.adobe.ac.pmd.rules.parsley.MismatchedManagedEventRule"
+ message="Managed events should have matching [Event] metadata">
+ <description>Each managed event should have matching [Event] metadata.</description>
+ <priority>1</priority>
+ <example>
+[Event(name="message", type="my.package.MyEvemt")]
+[ManagedEvents(names="messag")] // VIOLATION
+public class MyClass
+{
+}
+ </example>
+ </rule>
+
+ <rule
+ class="com.adobe.ac.pmd.rules.parsley.MessageInterceptorSignatureRule"
+ message="The signature of the message interceptor {0} is not correct. {1}.">
+ <description></description>
+ <priority>1</priority>
+ <example>
+ <![CDATA[
+[MessageInterceptor(type="a.b.MyMessage")]
+public function messageInterceptor( processor : MessageProcessor ) : void
+{
+ processor.proceed();
+}
+
+[MessageInterceptor(type="a.b.MyMessage")]
+public function messageInterceptor() : void // VIOLATION
+{
+}
+
+[MessageInterceptor(type="a.b.MyMessage")]
+public function messageInterceptor( type : MyMessage ) : void // VIOLATION
+{
+ type.something();
+}
+
+[MessageInterceptor(type="a.b.MyMessage")]
+public function messageInterceptor( processor : MessageProcessor, type : MyMessage ) : void // VIOLATION
+{
+}]]>
+ </example>
+ </rule>
+
+ <rule
+ class="com.adobe.ac.pmd.rules.parsley.MisplacedMetaDataRule"
+ message="This metadata {0} is misplaced">
+ <description></description>
+ <priority>1</priority>
+ <example>
+ </example>
+ </rule>
+
+ <rule
+ class="com.adobe.ac.pmd.rules.parsley.RedundantMessageHandlerTypeAttributeRule"
+ message="This type metadata argument is redundant with the handler argument type">
+ <description></description>
+ <priority>3</priority>
+ <example>
+ <![CDATA[
+[MessageHandler(type="a.b.MyMessage")] // VIOLATION
+public function doSomething( message : MyMessage ) : void
+{
+ message.toString();
+}]]>
+ </example>
+ </rule>
+
+ <rule
+ class="com.adobe.ac.pmd.rules.parsley.RedundantMethodAttributeRule"
+ message="This method metadata argument is redundant with the handler name">
+ <priority>3</priority>
+ <example> <![CDATA[
+[MessageHandler(method="doSomething")] // VIOLATION
+public function doSomething( message : MyMessage ) : void
+{
+ message.toString();
+}]]>
+ </example>
+ </rule>
+
+ <rule
+ class="com.adobe.ac.pmd.rules.parsley.UnknownMetaDataAttributeRule"
+ message="This metadata attribute {0} is unknown">
+ <description></description>
+ <priority>1</priority>
+ <example>
+ <![CDATA[
+[AsyncInit(x="y")] // VIOLATION
+public class UnknownMetaDataAttribute
+{
+ [Inject(x="y")] // VIOLATION
+ public var inject;
+
+ [MessageHandler(x="y")] // VIOLATION
+ public function messageHandler() : void
+ {
+ }
+}]]>
+ </example>
+ </rule>
+
+</ruleset>
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/performance.xml
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/performance.xml b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/performance.xml
new file mode 100644
index 0000000..ed46d9b
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/performance.xml
@@ -0,0 +1,115 @@
+<?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="Performance Rules"
+ xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd"
+ xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
+
+ <description>
+ This Ruleset contains a collection of good practices related to the performance (CPU and memory).
+ </description>
+
+ <rule class="com.adobe.ac.pmd.rules.performance.DynamicFiltersUsedInPopup"
+ message="A popup should not use dynamic filters">
+ <description>Prefer using embed filters in assets</description>
+ <priority>3</priority>
+ <example>
+ </example>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.performance.CyclomaticComplexityRule"
+ message="This method is too complex. Maximum complexity is {0}, but its cyclomatic complexity was {1}">
+ <priority>3</priority>
+ <properties>
+ <property name="maximum">
+ <value>10</value>
+ </property>
+ </properties>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.performance.HeavyConstructorRule"
+ message="Constructor must be as lightweight as possible. No control statement allowed, whereas a cyclomatic complexe of {0} has been detected">
+ <description><![CDATA[The Just-In-Time compiler does not compile constructors. Make them as lightweight as possible, or move the complexity of the code to a method called by the constructor. Then the complexity will be compiled by the JIT.]]></description>
+ <priority>3</priority>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.performance.CreationPolicySetToAllRule"
+ message="creationPolicy to ALL impacts the performance significantly">
+ <priority>1</priority>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.performance.BindableClassRule"
+ message="Globally bindable classes can lead to unexpected behaviour especially when you have a setter to a property, and hits the performance of the application">
+ <priority>3</priority>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.performance.AvoidInstanciationInLoopRule"
+ message="Instanciating a variable in a loop can be expensive">
+ <description></description>
+ <priority>5</priority>
+ <example>
+ </example>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.performance.AvoidDeclarationInLoopRule"
+ message="Declaring a variable in a loop can be expensive">
+ <description></description>
+ <priority>5</priority>
+ <example>
+ </example>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.performance.DeeplyNestedIfRule"
+ message="Nested if statements are not a good design">
+ <priority>3</priority>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.performance.RecursiveStyleManagerRule"
+ message="Detect calls to the StyleManager that don’t pass “false” as the second parameter">
+ <description>A recursive style manager call can be a very expensive operation, causing parts of the UI to flicker visibly. Instead it is preferable to defer the creation of parts of the UI that depend on a runtime CSS SWF until after the SWF has been loaded. In this case a recursive call is not required.</description>
+ <priority>3</priority>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.performance.AvoidUsingMathFloorRule"
+ message="VM will automatically do the rounding when using an int, so it should be : var position:int = floatingValue;">
+ <priority>5</priority>
+ <example>
+var position:Number = Math.floor ( floatingValue );
+ </example>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.performance.AvoidUsingMathCeilRule"
+ message="VM will automatically do the rounding when using an int, so should be : var position:int = floatingValue + 1;">
+ <priority>5</priority>
+ <example>
+var position:Number = Math.ceil ( floatingValue );
+ </example>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.performance.AvoidUsingMathRoundRule"
+ message="manual calculation will be much faster : var position:int = (floatingValue > 0.0) ? int(floatingValue + 0.5) : int(floatingValue - 0.5);">
+ <priority>5</priority>
+ <example>
+var position:Number = Math.round ( floatingValue );
+ </example>
+ </rule>
+
+</ruleset>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/security.xml
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/security.xml b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/security.xml
new file mode 100644
index 0000000..1955467
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/security.xml
@@ -0,0 +1,87 @@
+<?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="Security Rules"
+ xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd"
+ xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
+
+ <description>
+ The Security AS3 Ruleset contains a collection of best practices related to secure code.
+ </description>
+
+ <rule class="com.adobe.ac.pmd.rules.security.InsecureExactSettingsRule"
+ message="Security.exactSettings is set to an insecure value">
+ <description>The security.exactSettings value should remain set at the default true value. Setting this value to false could make the SWF vulnerable to cross-domain attacks.</description>
+ <priority>1</priority>
+ <example>
+ //exactSettings should be left as the default
+ Security.exactSettings = true;
+ </example>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.security.AllowAllSecureDomainRule"
+ message="Security.allowDomain is set to an insecure value">
+ <description>The security.allowDomain value of "*" will allow any domain to cross-script into the domain of this SWF and exercise its functionality.</description>
+ <priority>1</priority>
+ <example>
+ //The allowDomain settings should be specific
+ Security.allowDomain("www.example.org");
+ </example>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.security.LocalConnectionStarRule"
+ message="LocalConnection.allowDomain is set to an insecure value">
+ <description>The LocalConnection.allowDomain value of "*" will allow any domain to connect to this SWF and call its functions.</description>
+ <priority>1</priority>
+ <example>
+ //The allowDomain setting should be specific
+ LocalConnection.allowDomain("www.example.org");
+ </example>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.security.AllowInsecureDomainRule"
+ message="Potentially unnecessary use of allowInsecureDomain">
+ <description>Using allowInsecureDomain will allow untrusted content from an HTTP site to inject data into a trusted HTTPS connection which may comprimise the integrity of the HTTPS connection. The use of allowDomain is preferred.</description>
+ <priority>1</priority>
+ <example>
+ //Use the allowDomain setting instead
+ LocalConnection.allowDomain("www.example.org");
+ Security.allowDomain("www.example.org");
+ </example>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.security.LSOSecureFalseRule"
+ message="The secure flag is set to false">
+ <description>If this SWF is being served over HTTPS then the secure flag should be set to true. This can help prevent sensitive SSL protected information from being shared within insecure HTTP content. If this SWF is served over HTTP then you can ignore this warning.</description>
+ <priority>5</priority>
+ <example>
+ //Setting secure values for LSOs
+ LSO.getLocal(name, null, true);
+ </example>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.security.ImportLoadBestPracticeRule"
+ message="Set allowCodeImport to false when import loading images">
+ <description>If this loader is only intended to load image files (GIF,JPG,PNG) then be sure to set the allowCodeImport value to false. Setting this flag will reduce the chances of an untrusted SWF gaining access to your site. If your intent is to load a SWF, the URL for the request is a static value for a trusted site and/or you have already set the allowCodeImport flag, then you can ignore this warning.</description>
+ <priority>5</priority>
+ </rule>
+
+</ruleset>
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/sizing.xml
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/sizing.xml b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/sizing.xml
new file mode 100644
index 0000000..f2030bf
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/sizing.xml
@@ -0,0 +1,179 @@
+<?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="Sizing Rules"
+ xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd"
+ xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
+
+ <description>
+ The Sizing As3 Ruleset contains a collection of good practices related to code sizing.
+ </description>
+
+ <rule class="com.adobe.ac.pmd.rules.sizing.TooManyFunctionRule"
+ message="Too many methods detected ({0} maximum, but {1} actually)">
+ <description>A class with too many methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.</description>
+ <priority>3</priority>
+ <properties>
+ <property name="maximum">
+ <value>10</value>
+ </property>
+ </properties>
+ <example>
+ public class Foo
+ {
+ public function doWork() : void {}
+ public function doMoreWork() : void {}
+ public function doWorkAgain() : void {}
+ // [... more more public methods ...]
+ }
+ </example>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.sizing.TooLongFunctionRule"
+ message="This function is far too long ({0} maximum, but {1} actually)">
+ <description>Violations of this rule usually indicate that the method has too much responsibility. Try to reduce the method size by creating helper methods and removing any copy/pasted code.</description>
+ <priority>3</priority>
+ <properties>
+ <property name="maximum">
+ <value>20</value>
+ </property>
+ </properties>
+ <example>
+ public class Foo
+ {
+ public function doSomething() : void
+ {
+ System.out.println("Hello world!");
+ System.out.println("Hello world!");
+ // 98 copies omitted for brevity.
+ }
+ }
+ </example>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.sizing.TooLongSwitchCaseRule"
+ message="Long switch case detected ({0} lines maximum, but {1} actually)">
+ <description>A switch case statement should be either empty, or contain a break, or call another method.</description>
+ <priority>3</priority>
+ <properties>
+ <property name="maximum">
+ <value>3</value>
+ </property>
+ </properties>
+ <example>
+ public class Bar
+ {
+ public function foo() : void
+ {
+ var i : int = 4;
+
+ switch( i )
+ {
+ case 1:
+ handleFirstCase();
+ break;
+ case 2: // VIOLATION
+ googleResquest.url = "";
+ handleSecondCaseFirstPart();
+ handleSecondCaseSecondPart();
+ break;
+ }
+ }
+ }
+ </example>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.sizing.TooManyParametersRule"
+ message="Long parameter list detected ({0} maximum, but {1} actually)">
+ <description>Long parameter lists can indicate that a new object should be created to wrap the numerous parameters. Basically, try to group the parameters together.
+ </description>
+ <priority>3</priority>
+ <properties>
+ <property name="maximum">
+ <value>4</value>
+ </property>
+ </properties>
+ <example>
+ public class Foo
+ {
+ public function addData( p0 : int, p1 : int, p2 : int, p3 : int, p4 : int, p5 : int,
+ p6 : int, p7 : int, p8 : int, p9 : int, p10 : int ) : void
+ {
+ }
+ }
+ </example>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.sizing.TooManyPublicRule"
+ message="Too many public fields or functions detected ({0} maximum, but {1} actually)">
+ <description>A large number of public methods and attributes declared in a class can indicate the class may need to be broken up as increased effort will be required to thoroughly test it.</description>
+ <priority>3</priority>
+ <properties>
+ <property name="maximum">
+ <value>10</value>
+ </property>
+ </properties>
+ <example>
+ public class Foo
+ {
+ public var value : String;
+ public var something : Bar;
+ public var variable : Variable;
+
+ // [... more more public attributes ...]
+
+ public function doWork() : void {}
+ public function doMoreWork() : void {}
+ public function doWorkAgain() : void {}
+
+ // [... more more public methods ...]
+ }
+ </example>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.sizing.TooManyFieldsRule"
+ message="Too many field detected ({0} maximum, but {1} actually)">
+ <description>Classes that have too many fields could be redesigned to have fewer fields, possibly through some nested object grouping of some of the information. For example, a class with city/state/zipcode fields could instead have one Address field.</description>
+ <priority>3</priority>
+ <properties>
+ <property name="maximum">
+ <value>5</value>
+ </property>
+ </properties>
+ <example>
+ public class Person
+ {
+ private var one : String;
+ private var two : int;
+ private var three : int;
+
+ [... many more public fields ...]
+
+ }
+ </example>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.sizing.TooManyFieldInVORule"
+ message="Too many field detected ({0} maximum, but {1} actually)">
+ <priority>3</priority>
+ </rule>
+
+</ruleset>
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/style.xml
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/style.xml b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/style.xml
new file mode 100644
index 0000000..e60c32c
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/style.xml
@@ -0,0 +1,87 @@
+<?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="Style Rules"
+ xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.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.style.ConstructorNonEmptyReturnTypeRule"
+ message="A constructor should not have a return type">
+ <description>Even if this is syntactically correct, there should not be a return type for a constructor.</description>
+ <priority>5</priority>
+ <example>
+ public class VoidConstructor
+ {
+ public function VoidConstructor() : void // VIOLATION
+ {
+ }
+ }
+ </example>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.style.OverLongLineRule"
+ message="Too long line ({0} maximum, but {1} actually)">
+ <description></description>
+ <priority>5</priority>
+ <properties>
+ <property name="maximum">
+ <value>200</value>
+ </property>
+ </properties>
+ <example>
+ </example>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.style.ImportFromSamePackageRule"
+ message="Imports from the same package are not necessary">
+ <description></description>
+ <priority>5</priority>
+ <example>
+package com.adobe.ac
+{
+ import com.adobe.ac.MyModel; // VIOLATION HERE
+
+ public class BigModel
+ {
+ public var model : MyModel = null;
+ }
+}
+ </example>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.style.CopyrightMissingRule"
+ message="The copyright header is missing in this file">
+ <priority>5</priority>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.style.BadFormatLoggerRule"
+ message="The logger is not correctly formatted because {0}">
+ <description></description>
+ <priority>5</priority>
+ <example>
+ </example>
+ </rule>
+
+</ruleset>
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/switches.xml
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/switches.xml b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/switches.xml
new file mode 100644
index 0000000..ea8514f
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/switches.xml
@@ -0,0 +1,112 @@
+<?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="Switches Rules"
+ xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.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.switchrules.SwitchStatementsShouldHaveDefaultRule"
+ message="A switch statement does not contain a default statement">
+ <description>Switch statements should have a default label in order to detect corner cases.</description>
+ <priority>1</priority>
+ <example>
+public class Foo
+{
+ public funciton bar() : void
+ {
+ var x : int = 2;
+ switch (x)
+ {
+ case 2: var j : int = 8;
+ }
+ }
+}
+ </example>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.switchrules.NestedSwitchRule"
+ message="Switch must not be nested">
+ <description>As a general practice, switch statement should not be used. Prefer using inheritance. It is even harder to read when switch statements are nested.</description>
+ <priority>3</priority>
+ <example>
+public function foo( a : Number, b : Number ) : void
+{
+ switch( a )
+ {
+ case 1:
+ break;
+ case 2:
+ switch ( b )
+ {
+ case 3 :
+ break;
+ case 4 :
+ break;
+ }
+ break;
+ }
+}
+ </example>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.switchrules.NonBreakableSwitchCaseRule"
+ message="Switch case must include break statement">
+ <priority>1</priority>
+ <example>
+switch(event.type){
+ case GoogleSearchPanel.LAUNCH_GOOGLE_WEB_SEARCH:
+ googleResquest.url = ""; // VIOLATION
+ case GoogleSearchPanel.LAUNCH_GOOGLE_IMAGE_SEARCH:
+ case GoogleSearchPanel.LAUNCH_GOOGLE_IMAGE_SEARCH2:
+ googleResquest.url = "";
+ break;
+ default:
+ return;
+}
+ </example>
+ </rule>
+
+
+ <rule
+ class="com.adobe.ac.pmd.rules.switchrules.TooFewBrancheInSwitchStatementRule"
+ message="There are too few branches in this switch statement ({0} minimum, but {1} actual)">
+ <description>Switch statements are designed for complex branches, and allow branches to share treatment. Using a switch for only 2 branches is ill advised, as switches are not as easy to understand as if. In this case, it's most likely is a good idea to use a if statement</description>
+ <priority>5</priority>
+ <properties>
+ <property name="minimum">
+ <value>3</value>
+ </property>
+ </properties>
+ <example>
+ </example>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.switchrules.IdenticalSwitchCasesRule"
+ message="Two switch cases should not be identical">
+ <priority>1</priority>
+ </rule>
+
+</ruleset>
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/unused.xml
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/unused.xml b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/unused.xml
new file mode 100644
index 0000000..ed8fba2
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/resources/rulesets/flex/unused.xml
@@ -0,0 +1,83 @@
+<?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="Unused Rules"
+ xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.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.unused.UnusedParameterRule"
+ message="This parameter ({0}) of this function is not used">
+ <description>
+ </description>
+ <priority>3</priority>
+ <example>
+ public function foo( param1 : Number, param2 : Number, param3 : Number, param4 : Number, param5 : Number ) : void // 4 violations
+ {
+ var i : int = param1;
+ }
+ </example>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.unused.UnusedLocalVariableRule"
+ message="This variable ({0}) is not used">
+ <description>
+ </description>
+ <priority>3</priority>
+ <example>
+ public function foo() : void
+ {
+ var i : int = 0;// 1 violation
+ }
+ </example>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.unused.UnusedPrivateMethodRule"
+ message="This private method ({0}) does not seem to be used">
+ <description>
+ </description>
+ <priority>1</priority>
+ <example>
+ </example>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.unused.UnusedFieldRule"
+ message="This private attribute ({0}) does not seem to be used">
+ <description>
+ </description>
+ <priority>1</priority>
+ <example>
+ </example>
+ </rule>
+
+ <rule class="com.adobe.ac.pmd.rules.unused.EmptyPrivateMethodRule"
+ message="This private method ({0}) is used but its content is empty">
+ <description>
+ </description>
+ <priority>1</priority>
+ <example>
+ </example>
+ </rule>
+
+</ruleset>
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/AbstractAstFlexRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/AbstractAstFlexRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/AbstractAstFlexRuleTest.java
new file mode 100644
index 0000000..baf0887
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/AbstractAstFlexRuleTest.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.flex.pmd.rules;
+
+import org.apache.flex.pmd.files.IAs3File;
+import org.apache.flex.pmd.files.IFlexFile;
+import org.apache.flex.pmd.files.IMxmlFile;
+import org.apache.flex.pmd.nodes.IPackage;
+import org.apache.flex.pmd.nodes.impl.NodeFactory;
+import org.apache.flex.pmd.parser.exceptions.TokenException;
+import org.apache.flex.pmd.parser.impl.AS3Parser;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+public abstract class AbstractAstFlexRuleTest extends AbstractFlexRuleTest {
+ @Override
+ protected List<IFlexViolation> processFile(final String resourcePath) throws IOException,
+ TokenException {
+ if (!getIgnoreFiles().contains(resourcePath)) {
+ final AS3Parser parser = new AS3Parser(null);
+ final IFlexFile file = getTestFiles().get(resourcePath);
+
+ IPackage rootNode;
+
+ if (file == null) {
+ throw new IOException(resourcePath
+ + " is not found");
+ }
+ if (file instanceof IAs3File) {
+ rootNode = NodeFactory.createPackage(parser.buildAst(file.getFilePath()));
+ } else {
+ rootNode = NodeFactory.createPackage(parser.buildAst(file.getFilePath(),
+ ((IMxmlFile) file).getScriptBlock()));
+ }
+ return getRule().processFile(file,
+ rootNode,
+ getTestFiles());
+ }
+ return new ArrayList<IFlexViolation>();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/AbstractFlexRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/AbstractFlexRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/AbstractFlexRuleTest.java
new file mode 100644
index 0000000..ef9e358
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/AbstractFlexRuleTest.java
@@ -0,0 +1,223 @@
+/*
+ * 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 org.apache.flex.pmd.rules;
+
+import org.apache.flex.pmd.files.IFlexFile;
+import org.apache.flex.pmd.parser.exceptions.TokenException;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+import org.testng.annotations.Test;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.fail;
+
+public abstract class AbstractFlexRuleTest extends FlexPmdTestBase {
+ final static class AssertPosition {
+ public static AssertPosition create(final String message,
+ final int expectedLine,
+ final int actualLine) {
+ return new AssertPosition(message, expectedLine, actualLine);
+ }
+
+ public int actualLine;
+ public int expectedLine;
+ public String message;
+
+ private AssertPosition(final String messageToBeSet,
+ final int expectedLineToBeSet,
+ final int actualLineToBeSet) {
+ super();
+ message = messageToBeSet;
+ expectedLine = expectedLineToBeSet;
+ actualLine = actualLineToBeSet;
+ }
+ }
+
+ protected final static class ExpectedViolation {
+ protected String file;
+ protected ViolationPosition[] positions;
+
+ public ExpectedViolation(final String fileToBeSet,
+ final ViolationPosition[] positionsToBeSet) {
+ super();
+ file = fileToBeSet;
+ positions = positionsToBeSet;
+ }
+ }
+
+ protected static StringBuilder buildFailuresMessage(final List<AssertPosition> failures) {
+ final StringBuilder message = new StringBuilder(42);
+
+ for (final AssertPosition assertPosition : failures) {
+ message.append(assertPosition.message).append(": expected <").append(assertPosition.expectedLine);
+ message.append("> but actually <").append(assertPosition.actualLine).append(">\n");
+ }
+ return message;
+ }
+
+ protected static List<AssertPosition> buildFailureViolations(final String resourcePath,
+ final ViolationPosition[] expectedPositions,
+ final List<IFlexViolation> violations) {
+ List<AssertPosition> failures;
+ failures = new ArrayList<AssertPosition>();
+
+ for (int i = 0; i < expectedPositions.length; i++) {
+ final IFlexViolation violation = violations.get(i);
+ final ViolationPosition expectedPosition = expectedPositions[i];
+
+ if (expectedPosition.getBeginLine() != violation.getBeginLine()) {
+ failures.add(AssertPosition.create(BEGIN_LINE_NOT_CORRECT
+ + " at " + i + "th violation on " + resourcePath,
+ expectedPosition.getBeginLine(),
+ violation.getBeginLine()));
+ }
+ if (expectedPosition.getEndLine() != violation.getEndLine()) {
+ failures.add(AssertPosition.create(END_LINE_NOT_CORRECT
+ + " at " + i + "th violation on " + resourcePath,
+ expectedPosition.getEndLine(),
+ violation.getEndLine()));
+ }
+ }
+ return failures;
+ }
+
+ protected static StringBuilder buildMessageName(final Map<String, List<IFlexViolation>> violatedFiles) {
+ final StringBuilder buffer = new StringBuilder(100);
+
+ for (final String violatedFileName : violatedFiles.keySet()) {
+ final List<IFlexViolation> violations = violatedFiles.get(violatedFileName);
+
+ buffer.append(violatedFileName).append(" should not contain any violations ");
+ buffer.append(" (").append(violations.size()).append(" found");
+
+ if (violations.size() == 1) {
+ buffer.append(" at ").append(violations.get(0).getBeginLine()).append(":");
+ buffer.append(violations.get(0).getEndLine());
+ }
+ buffer.append(")\n");
+ }
+ return buffer;
+ }
+
+ /**
+ * Test case which contains non-concerned files by the given rule
+ *
+ * @throws TokenException
+ * @throws java.io.IOException
+ */
+ @Test
+ public final void testProcessNonViolatingFiles() throws IOException,
+ TokenException {
+ final Map<String, List<IFlexViolation>> violatedFiles = extractActualViolatedFiles();
+ final StringBuilder buffer = buildMessageName(violatedFiles);
+
+ if (!violatedFiles.isEmpty()) {
+ fail(buffer.toString());
+ }
+ }
+
+ /**
+ * Test case which contains violating files
+ */
+ @Test
+ public final void testProcessViolatingFiles() {
+ final Map<String, ViolationPosition[]> expectedPositions = computeExpectedViolations(getExpectedViolatingFiles());
+
+ for (final String fileName : expectedPositions.keySet()) {
+ assertViolations(fileName,
+ expectedPositions.get(fileName));
+ }
+ }
+
+ protected abstract ExpectedViolation[] getExpectedViolatingFiles();
+
+ protected List<String> getIgnoreFiles() {
+ return new ArrayList<String>();
+ }
+
+ protected abstract AbstractFlexRule getRule();
+
+ protected List<IFlexViolation> processFile(final String resourcePath) throws IOException,
+ TokenException {
+ if (!getIgnoreFiles().contains(resourcePath)) {
+ return getRule().processFile(getTestFiles().get(resourcePath),
+ null,
+ getTestFiles());
+ }
+ return new ArrayList<IFlexViolation>();
+ }
+
+ private void assertViolations(final String resourcePath,
+ final ViolationPosition[] expectedPositions) {
+ try {
+ final List<IFlexViolation> violations = processFile(resourcePath);
+
+ assertEquals(expectedPositions.length, violations.size(),
+ VIOLATIONS_NUMBER_NOT_CORRECT + " for " + resourcePath);
+
+ if (expectedPositions.length != 0) {
+ printFailures(buildFailureViolations(resourcePath,
+ expectedPositions,
+ violations));
+ }
+ } catch (final IOException e) {
+ fail(e.getMessage());
+ } catch (final TokenException e) {
+ fail(e.getMessage());
+ }
+ }
+
+ private Map<String, ViolationPosition[]> computeExpectedViolations(final ExpectedViolation[] expectedViolatingFiles) {
+ final Map<String, ViolationPosition[]> expectedViolations = new LinkedHashMap<String, ViolationPosition[]>();
+
+ for (final ExpectedViolation expectedViolatingFile : expectedViolatingFiles) {
+ expectedViolations.put(expectedViolatingFile.file,
+ expectedViolatingFile.positions);
+ }
+ return expectedViolations;
+ }
+
+ private Map<String, List<IFlexViolation>> extractActualViolatedFiles() throws IOException,
+ TokenException {
+ final Map<String, List<IFlexViolation>> violatedFiles = new LinkedHashMap<String, List<IFlexViolation>>();
+ final Map<String, ViolationPosition[]> expectedPositions = computeExpectedViolations(getExpectedViolatingFiles());
+
+ for (final Map.Entry<String, IFlexFile> fileNameEntry : getTestFiles().entrySet()) {
+ if (!expectedPositions.containsKey(fileNameEntry.getKey())) {
+ final List<IFlexViolation> violations = processFile(fileNameEntry.getKey());
+
+ if (!violations.isEmpty()) {
+ violatedFiles.put(fileNameEntry.getKey(),
+ violations);
+ }
+ }
+ }
+ return violatedFiles;
+ }
+
+ private void printFailures(final List<AssertPosition> failures) {
+ if (!failures.isEmpty()) {
+ fail(buildFailuresMessage(failures).toString());
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/AbstractRegExpBasedRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/AbstractRegExpBasedRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/AbstractRegExpBasedRuleTest.java
new file mode 100644
index 0000000..38afe1a
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/AbstractRegExpBasedRuleTest.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.flex.pmd.rules;
+
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.AbstractRegexpBasedRule;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+public abstract class AbstractRegExpBasedRuleTest extends AbstractFlexRuleTest {
+ @Test
+ public void testDoesCurrentLineMacthCorrectLine() {
+ final AbstractRegexpBasedRule rule = getRegexpBasedRule();
+
+ if (getMatchableLines().length == 0) {
+ Assert.fail("the getMatchableLines() is empty");
+ }
+ for (int i = 0; i < getMatchableLines().length; i++) {
+ final String correctLine = getMatchableLines()[i];
+
+ Assert.assertTrue(rule.doesCurrentLineMacthes(correctLine),
+ "This line (\"" + correctLine + "\") should be matched");
+ }
+ }
+
+ @Test
+ public void testDoesCurrentLineMacthIncorrectLine() {
+ final AbstractRegexpBasedRule rule = getRegexpBasedRule();
+
+ if (getUnmatchableLines().length == 0) {
+ Assert.fail("the getUnmatchableLines() is empty");
+ }
+ for (int i = 0; i < getUnmatchableLines().length; i++) {
+ final String incorrectLine = getUnmatchableLines()[i];
+
+ Assert.assertFalse(rule.doesCurrentLineMacthes(incorrectLine),
+ "This line (\"" + incorrectLine + "\") should not be matched");
+ }
+ }
+
+ protected abstract String[] getMatchableLines();
+
+ protected abstract AbstractRegexpBasedRule getRegexpBasedRule();
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return getRegexpBasedRule();
+ }
+
+ protected abstract String[] getUnmatchableLines();
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/FlexPmdTestBase.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/FlexPmdTestBase.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/FlexPmdTestBase.java
new file mode 100644
index 0000000..7388271
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/FlexPmdTestBase.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 org.apache.flex.pmd.rules;
+
+import org.apache.flex.pmd.files.IFlexFile;
+
+import java.io.File;
+import java.util.Map;
+
+/**
+ * This is a base class for any FlexPMD rule test case.
+ *
+ * @author xagnetti
+ */
+public class FlexPmdTestBase // NO_UCD
+{
+ protected static final String BEGIN_LINE_NOT_CORRECT = "Begining line is not correct"; // NO_UCD
+ protected static final String END_LINE_NOT_CORRECT = "Ending line is not correct"; // NO_UCD
+ protected static final String VIOLATIONS_NUMBER_NOT_CORRECT = "Violations number is not correct"; // NO_UCD
+
+ /**
+ * Test files placeholder. The key is the qualified file name
+ */
+ private Map<String, IFlexFile> testFiles = ResourcesManagerTest.getInstance()
+ .getTestFiles();
+
+ /**
+ *
+ */
+ protected FlexPmdTestBase() {
+ }
+
+ /**
+ * @return
+ */
+ protected File getTestDirectory() // NO_UCD
+ {
+ return ResourcesManagerTest.getInstance().getTestRootDirectory();
+ }
+
+ /**
+ * @return
+ */
+ protected final Map<String, IFlexFile> getTestFiles() // NO_UCD
+ {
+ return testFiles;
+ }
+
+ /**
+ * @param testFilesToBeSet
+ */
+ protected final void setTestFiles(final Map<String, IFlexFile> testFilesToBeSet) {
+ testFiles = testFilesToBeSet;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/ResourcesManagerTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/ResourcesManagerTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/ResourcesManagerTest.java
new file mode 100644
index 0000000..bca36f1
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/ResourcesManagerTest.java
@@ -0,0 +1,90 @@
+/*
+ * 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 org.apache.flex.pmd.rules;
+
+import net.sourceforge.pmd.PMDException;
+import org.apache.flex.pmd.files.IFlexFile;
+import org.apache.flex.pmd.files.impl.FileUtils;
+import org.apache.flex.pmd.utils.StackTraceUtils;
+
+import java.io.File;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.logging.Logger;
+
+/**
+ * Internal utility which finds out the test resources, and map them to their
+ * qualified names.
+ *
+ * @author xagnetti
+ */
+public final class ResourcesManagerTest {
+ private static ResourcesManagerTest instance = null;
+ private static final Logger LOGGER = Logger.getLogger(ResourcesManagerTest.class.getName());
+
+ /**
+ * @return
+ */
+ public static synchronized ResourcesManagerTest getInstance() // NOPMD
+ {
+ if (instance == null) {
+ try {
+// new LoggerUtils().loadConfiguration();
+ instance = new ResourcesManagerTest("/test");
+ } catch (final URISyntaxException e) {
+ LOGGER.warning(StackTraceUtils.print(e));
+ } catch (final PMDException e) {
+ LOGGER.warning(StackTraceUtils.print(e));
+ }
+ }
+ return instance;
+ }
+
+ private final Map<String, IFlexFile> testFiles;
+ private final File testRootDirectory;
+
+ private ResourcesManagerTest(final String directory) throws URISyntaxException,
+ PMDException {
+ final URL resource = this.getClass().getResource(directory);
+
+ if (resource == null) {
+ LOGGER.severe(directory
+ + " folder is not found in the resource");
+ testRootDirectory = null;
+ testFiles = new LinkedHashMap<String, IFlexFile>();
+ } else {
+ testRootDirectory = new File(resource.toURI().getPath());
+ testFiles = FileUtils.computeFilesList(testRootDirectory,
+ null,
+ "",
+ null);
+ }
+ }
+
+ /**
+ * @return
+ */
+ public Map<String, IFlexFile> getTestFiles() {
+ return testFiles;
+ }
+
+ protected File getTestRootDirectory() {
+ return testRootDirectory;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/architecture/MonkeyPatchingRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/architecture/MonkeyPatchingRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/architecture/MonkeyPatchingRuleTest.java
new file mode 100644
index 0000000..64aacd8
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/architecture/MonkeyPatchingRuleTest.java
@@ -0,0 +1,35 @@
+/*
+ * 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 org.apache.flex.pmd.rules.architecture;
+
+import org.apache.flex.pmd.rules.AbstractFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class MonkeyPatchingRuleTest extends AbstractFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("mx.controls.DateChooser2.as", new ViolationPosition[]
+ {new ViolationPosition(0)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new MonkeyPatchingRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/architecture/UseInternalClassOutsideApiClassTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/architecture/UseInternalClassOutsideApiClassTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/architecture/UseInternalClassOutsideApiClassTest.java
new file mode 100644
index 0000000..16bd49d
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/architecture/UseInternalClassOutsideApiClassTest.java
@@ -0,0 +1,45 @@
+/*
+ * 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 org.apache.flex.pmd.rules.architecture;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class UseInternalClassOutsideApiClassTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("functional.func2.restricted.Func2RestrictedClass.as", new ViolationPosition[]
+ {new ViolationPosition(22)}),
+ new ExpectedViolation("functional.func1.restricted.Func1RestrictedClass.as",
+ new ViolationPosition[]
+ {new ViolationPosition(23)}),
+ new ExpectedViolation("functional.func2.api.Func2ExposedClass.as", new ViolationPosition[]
+ {new ViolationPosition(22)}),
+ new ExpectedViolation("functional.func1.api.Func1ExposedClass.as", new ViolationPosition[]
+ {new ViolationPosition(24)}),
+ new ExpectedViolation("functional.FunctionalClient.as", new ViolationPosition[]
+ {new ViolationPosition(22),
+ new ViolationPosition(24)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new UseInternalClassOutsideApiClass();
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/architecture/ViewComponentReferencedInModelRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/architecture/ViewComponentReferencedInModelRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/architecture/ViewComponentReferencedInModelRuleTest.java
new file mode 100644
index 0000000..7840a2a
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/architecture/ViewComponentReferencedInModelRuleTest.java
@@ -0,0 +1,53 @@
+/*
+ * 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 org.apache.flex.pmd.rules.architecture;
+
+import org.apache.flex.pmd.rules.AbstractRegExpBasedRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractRegexpBasedRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class ViewComponentReferencedInModelRuleTest extends AbstractRegExpBasedRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("com.adobe.ac.ncss.BigImporterModel.as", new ViolationPosition[]
+ {new ViolationPosition(23)})};
+ }
+
+ @Override
+ protected String[] getMatchableLines() {
+ return new String[]
+ {"import lala.view.MyObject;",
+ "import MyObject ",
+ " import lala.view.MyObject"};
+ }
+
+ @Override
+ protected AbstractRegexpBasedRule getRegexpBasedRule() {
+ return new ViewComponentReferencedInModelRule();
+ }
+
+ @Override
+ protected String[] getUnmatchableLines() {
+ return new String[]
+ {"mport lala.view.MyObject",
+ " text=\"{ vfrfr().frfr.frf.lala }\"/>",
+ " text=\"{vfrfr().frfr.frf.lala}\"/>",
+ "public dynamic class DynamicObject {",
+ "dynamic public class DynamicObject"};
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/asdocs/AbstractAsDocRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/asdocs/AbstractAsDocRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/asdocs/AbstractAsDocRuleTest.java
new file mode 100644
index 0000000..3f87ff9
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/asdocs/AbstractAsDocRuleTest.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 org.apache.flex.pmd.rules.asdocs;
+
+import net.sourceforge.pmd.PMDException;
+import org.apache.flex.pmd.files.impl.FileUtils;
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+
+import java.io.File;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.logging.Logger;
+
+public abstract class AbstractAsDocRuleTest extends AbstractAstFlexRuleTest {
+ protected static final Logger LOGGER = Logger.getLogger(AbstractAsDocRuleTest.class.getName());
+ protected static final String TEST_FOLDER = "/asDocs";
+
+ public AbstractAsDocRuleTest() {
+ super();
+
+ final URL resource = this.getClass().getResource("/test"
+ + TEST_FOLDER);
+
+ if (resource != null) {
+ try {
+ setTestFiles(FileUtils.computeFilesList(new File(resource.toURI().getPath()),
+ null,
+ "",
+ null));
+ } catch (final PMDException e) {
+ LOGGER.warning(e.getLocalizedMessage());
+ } catch (final URISyntaxException e) {
+ LOGGER.warning(e.getLocalizedMessage());
+ }
+ }
+ }
+
+ @Override
+ protected File getTestDirectory() // NO_UCD
+ {
+ return new File(super.getTestDirectory().getAbsolutePath()
+ + TEST_FOLDER);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/asdocs/AttributeAsDocMissingRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/asdocs/AttributeAsDocMissingRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/asdocs/AttributeAsDocMissingRuleTest.java
new file mode 100644
index 0000000..b25f7e8
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/asdocs/AttributeAsDocMissingRuleTest.java
@@ -0,0 +1,34 @@
+/*
+ * 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 org.apache.flex.pmd.rules.asdocs;
+
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class AttributeAsDocMissingRuleTest extends AbstractAsDocRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("EmptyClass.as", new ViolationPosition[]
+ {new ViolationPosition(23)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new AttributeAsDocMissingRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/asdocs/ClassAsDocMissingRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/asdocs/ClassAsDocMissingRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/asdocs/ClassAsDocMissingRuleTest.java
new file mode 100644
index 0000000..4874a51
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/asdocs/ClassAsDocMissingRuleTest.java
@@ -0,0 +1,34 @@
+/*
+ * 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 org.apache.flex.pmd.rules.asdocs;
+
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class ClassAsDocMissingRuleTest extends AbstractAsDocRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("EmptyClass.as", new ViolationPosition[]
+ {new ViolationPosition(21)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new ClassAsDocMissingRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/asdocs/MethodAsDocMissingRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/asdocs/MethodAsDocMissingRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/asdocs/MethodAsDocMissingRuleTest.java
new file mode 100644
index 0000000..a427730
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/asdocs/MethodAsDocMissingRuleTest.java
@@ -0,0 +1,36 @@
+/*
+ * 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 org.apache.flex.pmd.rules.asdocs;
+
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class MethodAsDocMissingRuleTest extends AbstractAsDocRuleTest {
+
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("EmptyClass.as", new ViolationPosition[]
+ {new ViolationPosition(25),
+ new ViolationPosition(29)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new MethodAsDocMissingRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/binding/BindingUtilsRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/binding/BindingUtilsRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/binding/BindingUtilsRuleTest.java
new file mode 100644
index 0000000..e8823f2
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/binding/BindingUtilsRuleTest.java
@@ -0,0 +1,35 @@
+/*
+ * 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 org.apache.flex.pmd.rules.binding;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class BindingUtilsRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("cairngorm.FatController.as", new ViolationPosition[]
+ {new ViolationPosition(78)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new BindingUtilsRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/binding/ChangeWatcherRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/binding/ChangeWatcherRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/binding/ChangeWatcherRuleTest.java
new file mode 100644
index 0000000..f32c60b
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/binding/ChangeWatcherRuleTest.java
@@ -0,0 +1,35 @@
+/*
+ * 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 org.apache.flex.pmd.rules.binding;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class ChangeWatcherRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("AbstractRowData.as", new ViolationPosition[]
+ {new ViolationPosition(23)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new ChangeWatcherRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/binding/TooLongBindingExpressionRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/binding/TooLongBindingExpressionRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/binding/TooLongBindingExpressionRuleTest.java
new file mode 100644
index 0000000..20b7051
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/binding/TooLongBindingExpressionRuleTest.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 org.apache.flex.pmd.rules.binding;
+
+import org.apache.flex.pmd.rules.AbstractRegExpBasedRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractRegexpBasedRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class TooLongBindingExpressionRuleTest extends AbstractRegExpBasedRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("com.adobe.ac.ncss.mxml.IterationsList2.mxml", new ViolationPosition[]
+ {new ViolationPosition(40)})};
+ }
+
+ @Override
+ protected String[] getMatchableLines() {
+ return new String[]
+ {" text=\"{ vfrfr.frfr.frf.lala }\"/>",
+ " text=\"{ vfrfr().frfr.frf.lala }\"/>",
+ " text=\"{vfrfr().frfr.frf.lala}\"/>"};
+ }
+
+ @Override
+ protected AbstractRegexpBasedRule getRegexpBasedRule() {
+ return new TooLongBindingExpressionRule();
+ }
+
+ @Override
+ protected String[] getUnmatchableLines() {
+ return new String[]
+ {" text=\"\"/>",
+ "lala()",
+ "<mx:Label text=\"{'a.b.c.d.e.f'}\" /> "};
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/cairngorm/BadCairngormEventNameFormatRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/cairngorm/BadCairngormEventNameFormatRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/cairngorm/BadCairngormEventNameFormatRuleTest.java
new file mode 100644
index 0000000..4b773bf
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/cairngorm/BadCairngormEventNameFormatRuleTest.java
@@ -0,0 +1,38 @@
+/*
+ * 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 org.apache.flex.pmd.rules.cairngorm;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class BadCairngormEventNameFormatRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ final ViolationPosition[] positions =
+ {new ViolationPosition(26)};
+
+ return new ExpectedViolation[]
+ {new ExpectedViolation("cairngorm.events.UncorrectConstructorEvent.as", positions),
+ new ExpectedViolation("cairngorm.events.UncorrectConstantEvent.as", positions)};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new BadCairngormEventNameFormatRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/cairngorm/BindableModelLocatorRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/cairngorm/BindableModelLocatorRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/cairngorm/BindableModelLocatorRuleTest.java
new file mode 100644
index 0000000..7941e0c
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/cairngorm/BindableModelLocatorRuleTest.java
@@ -0,0 +1,35 @@
+/*
+ * 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 org.apache.flex.pmd.rules.cairngorm;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class BindableModelLocatorRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("cairngorm.BindableModelLocator.as", new ViolationPosition[]
+ {new ViolationPosition(21)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new BindableModelLocatorRule();
+ }
+}
[18/24] git commit: [flex-utilities]
[refs/heads/feature/pmd-5.2-language-module] - Initial commit of the PMD
language module for Apache Flex
Posted by cd...@apache.org.
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/files/impl/MxmlFile.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/files/impl/MxmlFile.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/files/impl/MxmlFile.java
new file mode 100644
index 0000000..49b49ed
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/files/impl/MxmlFile.java
@@ -0,0 +1,291 @@
+/*
+ * 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 org.apache.flex.pmd.files.impl;
+
+import org.apache.flex.pmd.files.IMxmlFile;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author xagnetti
+ */
+class MxmlFile extends AbstractFlexFile implements IMxmlFile {
+ private static final String METADATA_TAG = "Metadata";
+ private String[] actualScriptBlock;
+ private int endLine;
+ private boolean mainApplication = false;
+ private String[] scriptBlock;
+ private int startLine;
+
+ /**
+ * @param file
+ * @param rootDirectory
+ */
+ protected MxmlFile(final File file,
+ final File rootDirectory) {
+ super(file, rootDirectory);
+
+ computeIfIsMainApplication();
+ if (getLinesNb() > 0) {
+ extractScriptBlock();
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.files.IMxmlFile#getActualScriptBlock()
+ */
+ public final String[] getActualScriptBlock() {
+ return actualScriptBlock; // NOPMD
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.files.IMxmlFile#getBeginningScriptBlock()
+ */
+ public int getBeginningScriptBlock() {
+ return startLine;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.files.impl.AbstractFlexFile#getCommentClosingTag()
+ */
+ @Override
+ public final String getCommentClosingTag() {
+ return "-->";
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.files.impl.AbstractFlexFile#getCommentOpeningTag()
+ */
+ @Override
+ public final String getCommentOpeningTag() {
+ return "<!--";
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.files.IMxmlFile#getEndingScriptBlock()
+ */
+ public int getEndingScriptBlock() {
+ return endLine;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.files.IMxmlFile#getScriptBlock()
+ */
+ public final String[] getScriptBlock() {
+ return scriptBlock; // NOPMD by xagnetti on 7/7/09 3:15 PM
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.files.IFlexFile#getSingleLineComment()
+ */
+ public String getSingleLineComment() {
+ return getCommentOpeningTag();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.files.impl.AbstractFlexFile#isMainApplication()
+ */
+ @Override
+ public final boolean isMainApplication() {
+ return mainApplication;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.files.impl.AbstractFlexFile#isMxml()
+ */
+ @Override
+ public final boolean isMxml() {
+ return true;
+ }
+
+ private void computeIfIsMainApplication() {
+ for (final String line : getLines()) {
+ if (line.contains("Application ")
+ && line.charAt(0) == '<') {
+ mainApplication = true;
+ break;
+ }
+ }
+ }
+
+ private int computeScriptOffSet(final int startingLineIndex) {
+ int currentLineIndex = startingLineIndex + 1;
+ while (getLines().get(currentLineIndex).contains("CDATA[")
+ || getLines().get(currentLineIndex).contains("//") || containsCloseComment(currentLineIndex)
+ || getLines().get(currentLineIndex).trim().equals("")) {
+ currentLineIndex++;
+ }
+ return currentLineIndex
+ - startingLineIndex;
+ }
+
+ private boolean containsCloseComment(final int currentLineIndex) {
+ final boolean closedAsComment = getLines().get(currentLineIndex).contains("/*")
+ && getLines().get(currentLineIndex).contains("*/");
+ final boolean closeMxmlComment = getLines().get(currentLineIndex).contains("<!--")
+ && getLines().get(currentLineIndex).contains("-->");
+ return closedAsComment
+ || closeMxmlComment;
+ }
+
+ private void copyScriptLinesKeepingOriginalLineIndices() {
+ final List<String> scriptLines = extractScriptLines();
+ final List<String> metaDataLines = extractMetaDataLines();
+ final String packageLine = "package "
+ + getPackageName() + "{";
+ final String classLine = "class "
+ + getClassName().split("\\.")[0] + "{";
+
+ scriptLines.set(0,
+ packageLine);
+
+ if (metaDataLines.isEmpty()
+ || metaDataLines.get(0).compareTo("HostComponent") == 0) {
+ if (scriptLines.size() > 1) {
+ scriptLines.set(1,
+ classLine);
+ }
+ } else {
+ final int firstMetaDataLine = getFirstMetaDataLine(getLines());
+
+ for (int i = firstMetaDataLine; i < firstMetaDataLine
+ + metaDataLines.size(); i++) {
+ scriptLines.set(i,
+ metaDataLines.get(i
+ - firstMetaDataLine));
+ }
+ scriptLines.set(firstMetaDataLine
+ + metaDataLines.size(),
+ classLine);
+ }
+
+ scriptLines.set(scriptLines.size() - 1,
+ "}}");
+ scriptBlock = scriptLines.toArray(new String[scriptLines.size()]);
+ }
+
+ private List<String> extractMetaDataLines() {
+ final ArrayList<String> metaDataLines = new ArrayList<String>();
+ int currentLineIndex = 0;
+ int start = 0;
+ int end = 0;
+
+ for (final String line : getLines()) {
+ if (line.contains(METADATA_TAG)) {
+ if (line.contains("</")) {
+ end = currentLineIndex
+ - (getLines().get(currentLineIndex - 1).contains("]]>") ? 1
+ : 0);
+ if (line.contains("<fx")
+ || line.contains("<mx")) {
+ start = end;
+ }
+ break;
+ }
+ if (line.contains("<")) {
+ start = currentLineIndex
+ + (getLines().get(currentLineIndex + 1).contains("CDATA[") ? 2
+ : 1);
+ }
+ }
+ currentLineIndex++;
+ }
+ metaDataLines.addAll(getLines().subList(start,
+ end));
+ return metaDataLines;
+ }
+
+ private void extractScriptBlock() {
+ int currentLineIndex = 0;
+ startLine = 0;
+ endLine = 0;
+
+ for (final String line : getLines()) {
+ if (line.contains("Script")) {
+ if (line.contains("</")) {
+ endLine = currentLineIndex
+ - (getLines().get(currentLineIndex - 1).contains("]]>") ? 1
+ : 0);
+ break;
+ } else if (line.contains("<")) {
+ startLine = currentLineIndex
+ + computeScriptOffSet(currentLineIndex);
+ }
+ }
+ currentLineIndex++;
+ }
+
+ copyScriptLinesKeepingOriginalLineIndices();
+ }
+
+ private List<String> extractScriptLines() {
+ final List<String> scriptLines = new ArrayList<String>();
+
+ for (int j = 0; j < startLine; j++) {
+ scriptLines.add("");
+ }
+ if (startLine < endLine) {
+ actualScriptBlock = getLines().subList(startLine,
+ endLine).toArray(new String[endLine
+ - startLine]);
+ scriptLines.addAll(new ArrayList<String>(getLines().subList(startLine,
+ endLine)));
+ }
+ for (int j = endLine; j < getLines().size(); j++) {
+ scriptLines.add("");
+ }
+ return scriptLines;
+ }
+
+ private int getFirstMetaDataLine(final List<String> lines) {
+ for (int i = 0; i < lines.size(); i++) {
+ final String line = lines.get(i);
+
+ if (line.contains(METADATA_TAG)
+ && line.contains("<")) {
+ return i;
+ }
+ }
+ return 0;
+ }
+
+ // private String printMetaData( final List< String > metaDataLines )
+ // {
+ // final StringBuffer buffer = new StringBuffer();
+ // if ( metaDataLines == null
+ // || metaDataLines.isEmpty() )
+ // {
+ // return "";
+ // }
+ // for ( final String line : metaDataLines )
+ // {
+ // buffer.append( line );
+ // }
+ // return buffer + " ";
+ // }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IAsDocHolder.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IAsDocHolder.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IAsDocHolder.java
new file mode 100644
index 0000000..da3359c
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IAsDocHolder.java
@@ -0,0 +1,29 @@
+/*
+ * 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 org.apache.flex.pmd.nodes;
+
+import org.apache.flex.pmd.parser.IParserNode;
+
+/**
+ * @author xagnetti
+ */
+public interface IAsDocHolder extends INode {
+ /**
+ * @return AsDoc information
+ */
+ IParserNode getAsDoc();
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IAttribute.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IAttribute.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IAttribute.java
new file mode 100644
index 0000000..1be3102
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IAttribute.java
@@ -0,0 +1,23 @@
+/*
+ * 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 org.apache.flex.pmd.nodes;
+
+/**
+ * @author xagnetti
+ */
+public interface IAttribute extends IField {
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IClass.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IClass.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IClass.java
new file mode 100644
index 0000000..fbe4ad0
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IClass.java
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.flex.pmd.nodes;
+
+import org.apache.flex.pmd.parser.IParserNode;
+
+import java.util.List;
+
+/**
+ * Node representing a class. It contains different lists (constants, variables,
+ * functions, implementations, ...), but also a reference to its constructor (if
+ * any), the extension name (if any), and its name.
+ *
+ * @author xagnetti
+ */
+public interface IClass extends IVisible, IMetaDataListHolder, INamableNode, IAsDocHolder, ICommentHolder {
+ /**
+ * @return
+ */
+ List<IAttribute> getAttributes();
+
+ /**
+ * @return
+ */
+ double getAverageCyclomaticComplexity();
+
+ /**
+ * @return
+ */
+ IParserNode getBlock();
+
+ /**
+ * @return
+ */
+ List<IConstant> getConstants();
+
+ /**
+ * @return
+ */
+ IFunction getConstructor();
+
+ /**
+ * @return
+ */
+ String getExtensionName();
+
+ /**
+ * @return
+ */
+ List<IFunction> getFunctions();
+
+ /**
+ * @return
+ */
+ List<IParserNode> getImplementations();
+
+ /**
+ * @return
+ */
+ boolean isBindable();
+
+ /**
+ * @return
+ */
+ boolean isFinal();
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/ICommentHolder.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/ICommentHolder.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/ICommentHolder.java
new file mode 100644
index 0000000..b74df5a
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/ICommentHolder.java
@@ -0,0 +1,31 @@
+/*
+ * 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 org.apache.flex.pmd.nodes;
+
+import org.apache.flex.pmd.parser.IParserNode;
+
+import java.util.List;
+
+/**
+ * @author xagnetti
+ */
+public interface ICommentHolder {
+ /**
+ * @return
+ */
+ List<IParserNode> getMultiLinesComment();
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IConstant.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IConstant.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IConstant.java
new file mode 100644
index 0000000..3bc7a81
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IConstant.java
@@ -0,0 +1,23 @@
+/*
+ * 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 org.apache.flex.pmd.nodes;
+
+/**
+ * @author xagnetti
+ */
+public interface IConstant extends IField {
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IField.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IField.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IField.java
new file mode 100644
index 0000000..1576b8d
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IField.java
@@ -0,0 +1,27 @@
+/*
+ * 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 org.apache.flex.pmd.nodes;
+
+/**
+ * @author xagnetti
+ */
+public interface IField extends IVariable, IVisible, IAsDocHolder {
+ /**
+ * @return
+ */
+ boolean isStatic();
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IFieldInitialization.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IFieldInitialization.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IFieldInitialization.java
new file mode 100644
index 0000000..5e20e08
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IFieldInitialization.java
@@ -0,0 +1,23 @@
+/*
+ * 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 org.apache.flex.pmd.nodes;
+
+/**
+ * @author xagnetti
+ */
+public interface IFieldInitialization extends INode {
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IFunction.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IFunction.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IFunction.java
new file mode 100644
index 0000000..90a9d8e
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IFunction.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 org.apache.flex.pmd.nodes;
+
+import org.apache.flex.pmd.parser.IParserNode;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Node representing a Function It contains the function name, its parameters,
+ * its return type, its modifiers, its metadata
+ *
+ * @author xagnetti
+ */
+public interface IFunction extends IVisible, IMetaDataListHolder, INamableNode, IAsDocHolder, ICommentHolder {
+ /**
+ * Finds recursively a statement in the function body from a list of names
+ *
+ * @param primaryNames statement name
+ * @return corresponding node
+ */
+ List<IParserNode> findPrimaryStatementInBody(final String[] primaryNames);
+
+ /**
+ * Finds recursively a statement in the function body from its name
+ *
+ * @param primaryName statement name
+ * @return corresponding node
+ */
+ List<IParserNode> findPrimaryStatementsInBody(final String primaryName);
+
+ /**
+ * @return
+ */
+ IParserNode getBody();
+
+ /**
+ * @return
+ */
+ int getCyclomaticComplexity();
+
+ /**
+ * @return
+ */
+ Map<String, IParserNode> getLocalVariables();
+
+ /**
+ * @return
+ */
+ List<IParameter> getParameters();
+
+ /**
+ * @return
+ */
+ IIdentifierNode getReturnType();
+
+ /**
+ * @return
+ */
+ int getStatementNbInBody();
+
+ /**
+ * @return Extracts the super call node (if any) from the function content
+ * block
+ */
+ IParserNode getSuperCall();
+
+ boolean isEventHandler();
+
+ /**
+ * @return
+ */
+ boolean isGetter();
+
+ /**
+ * @return
+ */
+ boolean isOverriden();
+
+ /**
+ * @return
+ */
+ boolean isSetter();
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IIdentifierNode.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IIdentifierNode.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IIdentifierNode.java
new file mode 100644
index 0000000..3af0cf7
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IIdentifierNode.java
@@ -0,0 +1,24 @@
+/*
+ * 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 org.apache.flex.pmd.nodes;
+
+/**
+ * @author xagnetti
+ */
+public interface IIdentifierNode extends INode {
+
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IMetaData.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IMetaData.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IMetaData.java
new file mode 100644
index 0000000..b7176c4
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IMetaData.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 org.apache.flex.pmd.nodes;
+
+import java.util.List;
+
+/**
+ * @author xagnetti
+ */
+public interface IMetaData extends INamable, INode {
+ /**
+ * @return
+ */
+ List<String> getAttributeNames();
+
+ /**
+ * @return
+ */
+ String getDefaultValue();
+
+ /**
+ * @param property
+ * @return
+ */
+ String[] getProperty(final String property);
+
+ /**
+ * @param property
+ * @return
+ */
+ List<String> getPropertyAsList(final String property);
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IMetaDataListHolder.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IMetaDataListHolder.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IMetaDataListHolder.java
new file mode 100644
index 0000000..3e30852
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IMetaDataListHolder.java
@@ -0,0 +1,45 @@
+/*
+ * 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 org.apache.flex.pmd.nodes;
+
+import java.util.List;
+
+/**
+ * @author xagnetti
+ */
+public interface IMetaDataListHolder {
+ /**
+ * @param metaData
+ */
+ void add(IMetaData metaData);
+
+ /**
+ * @return
+ */
+ List<IMetaData> getAllMetaData();
+
+ /**
+ * @param metaDataName
+ * @return
+ */
+ List<IMetaData> getMetaData(MetaData metaDataName);
+
+ /**
+ * @return
+ */
+ int getMetaDataCount();
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IModifiersHolder.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IModifiersHolder.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IModifiersHolder.java
new file mode 100644
index 0000000..072b544
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IModifiersHolder.java
@@ -0,0 +1,33 @@
+/*
+ * 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 org.apache.flex.pmd.nodes;
+
+/**
+ * @author xagnetti
+ */
+public interface IModifiersHolder {
+ /**
+ * @param modifier
+ */
+ void add(Modifier modifier);
+
+ /**
+ * @param modifier
+ * @return
+ */
+ boolean is(Modifier modifier); // NOPMD
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/INamable.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/INamable.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/INamable.java
new file mode 100644
index 0000000..1cf0dfd
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/INamable.java
@@ -0,0 +1,27 @@
+/*
+ * 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 org.apache.flex.pmd.nodes;
+
+/**
+ * @author xagnetti
+ */
+public interface INamable {
+ /**
+ * @return
+ */
+ String getName();
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/INamableNode.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/INamableNode.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/INamableNode.java
new file mode 100644
index 0000000..a83e996
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/INamableNode.java
@@ -0,0 +1,24 @@
+/*
+ * 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 org.apache.flex.pmd.nodes;
+
+/**
+ * @author xagnetti
+ */
+public interface INamableNode extends INode, INamable {
+
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/INode.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/INode.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/INode.java
new file mode 100644
index 0000000..d2698ae
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/INode.java
@@ -0,0 +1,31 @@
+/*
+ * 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 org.apache.flex.pmd.nodes;
+
+import org.apache.flex.pmd.parser.IParserNode;
+
+/**
+ * FlexPmdNode which wraps the parser node into a concrete type
+ *
+ * @author xagnetti
+ */
+public interface INode {
+ /**
+ * @return
+ */
+ IParserNode getInternalNode();
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IPackage.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IPackage.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IPackage.java
new file mode 100644
index 0000000..f15cfbe
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IPackage.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.flex.pmd.nodes;
+
+import org.apache.flex.pmd.parser.IParserNode;
+
+import java.util.List;
+
+/**
+ * Node representing a package. It contains the nested class node, the list of
+ * imports, and the package name.
+ *
+ * @author xagnetti
+ */
+public interface IPackage extends INamable, INode {
+ /**
+ * @return
+ */
+ IClass getClassNode();
+
+ /**
+ * @return
+ */
+ String getFullyQualifiedClassName();
+
+ /**
+ * @return
+ */
+ List<IFunction> getFunctions();
+
+ /**
+ * @return
+ */
+ List<IParserNode> getImports();
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IParameter.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IParameter.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IParameter.java
new file mode 100644
index 0000000..425f833
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IParameter.java
@@ -0,0 +1,23 @@
+/*
+ * 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 org.apache.flex.pmd.nodes;
+
+/**
+ * @author xagnetti
+ */
+public interface IParameter extends IVariable {
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IVariable.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IVariable.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IVariable.java
new file mode 100644
index 0000000..e0f1caa
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IVariable.java
@@ -0,0 +1,32 @@
+/*
+ * 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 org.apache.flex.pmd.nodes;
+
+/**
+ * @author xagnetti
+ */
+public interface IVariable extends IMetaDataListHolder, INamableNode {
+ /**
+ * @return
+ */
+ IFieldInitialization getInitializationExpression();
+
+ /**
+ * @return
+ */
+ IIdentifierNode getType();
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IVisible.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IVisible.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IVisible.java
new file mode 100644
index 0000000..660a898
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/IVisible.java
@@ -0,0 +1,27 @@
+/*
+ * 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 org.apache.flex.pmd.nodes;
+
+/**
+ * @author xagnetti
+ */
+public interface IVisible extends IModifiersHolder {
+ /**
+ * @return
+ */
+ boolean isPublic();
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/MetaData.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/MetaData.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/MetaData.java
new file mode 100644
index 0000000..465136b
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/MetaData.java
@@ -0,0 +1,78 @@
+/*
+ * 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 org.apache.flex.pmd.nodes;
+
+/**
+ * @author xagnetti
+ */
+public enum MetaData {
+ ARRAY_ELEMENT_TYPE("ArrayElementType"),
+ BEFORE("Before"),
+ BINDABLE("Bindable"),
+ DEFAULT_PROPERTY("DefaultProperty"),
+ DEPRECATED("Deprecated"),
+ EFFECT("Effect"),
+ EMBED("Embed"),
+ EVENT("Event"),
+ EXCLUDE("Exclude"),
+ EXCLUDE_CLASS("Exclude"),
+ ICON_FILE("IconFile"),
+ INSPECTABLE("Inspectable"),
+ INSTANCE_TYPE("InstanceType"),
+ NON_COMITTING_CHANGE_EVENT("NonCommittingChangeEvent"),
+ OTHER("Other"),
+ REMOTE_CLASS("RemoteClass"),
+ STYLE("Style"),
+ TEST("Test"),
+ TRANSIENT("Transient");
+
+ /**
+ * @param metaDataName
+ * @return
+ */
+ public static MetaData create(final String metaDataName) {
+ MetaData metaData = null;
+
+ for (final MetaData currentMetadata : values()) {
+ if (currentMetadata.toString().compareTo(metaDataName) == 0) {
+ metaData = currentMetadata;
+ break;
+ }
+ }
+ if (metaData == null) {
+ metaData = MetaData.OTHER;
+ metaData.name = metaDataName;
+ }
+
+ return metaData;
+ }
+
+ private String name;
+
+ private MetaData(final String nameToBeSet) {
+ name = nameToBeSet;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.lang.Enum#toString()
+ */
+ @Override
+ public String toString() {
+ return name;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/Modifier.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/Modifier.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/Modifier.java
new file mode 100644
index 0000000..c00999e
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/Modifier.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.flex.pmd.nodes;
+
+import org.apache.flex.pmd.parser.KeyWords;
+
+/**
+ * @author xagnetti
+ */
+public enum Modifier {
+ DYNAMIC, FINAL, INTERNAL, OVERRIDE, PRIVATE, PROTECTED, PUBLIC, STATIC, INTRINSIC;
+
+ /**
+ * @param name
+ * @return
+ */
+ public static Modifier create(final String name) {
+ Modifier modifier = null;
+ if (KeyWords.PUBLIC.toString().equals(name)) {
+ modifier = Modifier.PUBLIC;
+ } else if (KeyWords.PRIVATE.toString().equals(name)) {
+ modifier = Modifier.PRIVATE;
+ } else if (KeyWords.PROTECTED.toString().equals(name)) {
+ modifier = Modifier.PROTECTED;
+ } else if (KeyWords.INTERNAL.toString().equals(name)) {
+ modifier = Modifier.INTERNAL;
+ } else if (KeyWords.DYNAMIC.toString().equals(name)) {
+ modifier = Modifier.DYNAMIC;
+ } else if (KeyWords.OVERRIDE.toString().equals(name)) {
+ modifier = Modifier.OVERRIDE;
+ } else if (KeyWords.STATIC.toString().equals(name)) {
+ modifier = Modifier.STATIC;
+ } else if (KeyWords.FINAL.toString().equals(name)) {
+ modifier = Modifier.FINAL;
+ }
+ // class modifier AS2
+ else if (KeyWords.INTRINSIC.toString().equals(name)) {
+ modifier = Modifier.INTRINSIC;
+ }
+ return modifier;
+ }
+
+ private Modifier() {
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/asdoc/impl/AsDocNodeBase.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/asdoc/impl/AsDocNodeBase.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/asdoc/impl/AsDocNodeBase.java
new file mode 100644
index 0000000..5c7a335
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/asdoc/impl/AsDocNodeBase.java
@@ -0,0 +1,39 @@
+/*
+ * 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 org.apache.flex.pmd.nodes.asdoc.impl;
+
+/**
+ * @author xagnetti
+ */
+public class AsDocNodeBase {
+ private final String description;
+
+ /**
+ * @param descriptionToBeSet
+ */
+ public AsDocNodeBase(final String descriptionToBeSet) {
+ super();
+ description = descriptionToBeSet;
+ }
+
+ /**
+ * @return
+ */
+ public String getDescription() {
+ return description;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/asdoc/impl/ClassAsDocNode.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/asdoc/impl/ClassAsDocNode.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/asdoc/impl/ClassAsDocNode.java
new file mode 100644
index 0000000..3efb8aa
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/asdoc/impl/ClassAsDocNode.java
@@ -0,0 +1,29 @@
+/*
+ * 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 org.apache.flex.pmd.nodes.asdoc.impl;
+
+/**
+ * @author xagnetti
+ */
+public class ClassAsDocNode extends AsDocNodeBase {
+ /**
+ * @param descriptionToBeSet
+ */
+ public ClassAsDocNode(final String descriptionToBeSet) {
+ super(descriptionToBeSet);
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/asdoc/impl/FunctionAsDocNode.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/asdoc/impl/FunctionAsDocNode.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/asdoc/impl/FunctionAsDocNode.java
new file mode 100644
index 0000000..61b3206
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/asdoc/impl/FunctionAsDocNode.java
@@ -0,0 +1,50 @@
+/*
+ * 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 org.apache.flex.pmd.nodes.asdoc.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author xagnetti
+ */
+public class FunctionAsDocNode extends AsDocNodeBase {
+ private final List<ParameterAsDocNode> parameters;
+
+ /**
+ * @param descriptionToBeSet
+ */
+ public FunctionAsDocNode(final String descriptionToBeSet) {
+ super(descriptionToBeSet);
+ parameters = new ArrayList<ParameterAsDocNode>();
+ }
+
+ /**
+ * @param param
+ */
+ public void addParameter(final ParameterAsDocNode param) {
+ parameters.add(param);
+ }
+
+ /**
+ * @param index
+ * @return
+ */
+ public ParameterAsDocNode getParameter(final int index) {
+ return parameters.get(index);
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/asdoc/impl/ParameterAsDocNode.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/asdoc/impl/ParameterAsDocNode.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/asdoc/impl/ParameterAsDocNode.java
new file mode 100644
index 0000000..e7ac3fd
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/asdoc/impl/ParameterAsDocNode.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 org.apache.flex.pmd.nodes.asdoc.impl;
+
+/**
+ * @author xagnetti
+ */
+public class ParameterAsDocNode {
+ private final String description;
+ private final String name;
+
+ /**
+ * @param nameToBeSet
+ * @param descriptionToBeSet
+ */
+ public ParameterAsDocNode(final String nameToBeSet,
+ final String descriptionToBeSet) {
+ super();
+
+ name = nameToBeSet;
+ description = descriptionToBeSet;
+ }
+
+ /**
+ * @return
+ */
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * @return
+ */
+ public String getName() {
+ return name;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/impl/AbstractNode.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/impl/AbstractNode.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/impl/AbstractNode.java
new file mode 100644
index 0000000..f5c5dc5
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/impl/AbstractNode.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 org.apache.flex.pmd.nodes.impl;
+
+import org.apache.flex.pmd.nodes.IMetaDataListHolder;
+import org.apache.flex.pmd.nodes.IModifiersHolder;
+import org.apache.flex.pmd.nodes.INode;
+import org.apache.flex.pmd.nodes.Modifier;
+import org.apache.flex.pmd.parser.IParserNode;
+
+import java.util.logging.Logger;
+
+/**
+ * @author xagnetti
+ */
+abstract class AbstractNode implements INode {
+ protected static final Logger LOGGER = Logger.getLogger("Node");
+
+ /**
+ * @param metaDataHolder
+ * @param child
+ */
+ protected static void computeMetaDataList(final IMetaDataListHolder metaDataHolder,
+ final IParserNode child) {
+ if (child.numChildren() != 0) {
+ for (final IParserNode metadataNode : child.getChildren()) {
+ metaDataHolder.add(NodeFactory.createMetaData(metadataNode));
+ }
+ }
+ }
+
+ /**
+ * @param modifiable
+ * @param child
+ */
+ protected static final void computeModifierList(final IModifiersHolder modifiable,
+ final IParserNode child) {
+ if (child.numChildren() != 0) {
+ for (final IParserNode modifierNode : child.getChildren()) {
+ final Modifier modifier = Modifier.create(modifierNode.getStringValue());
+
+ modifiable.add(modifier);
+ }
+ }
+ }
+
+ private final IParserNode internalNode;
+
+ /**
+ * @param node
+ */
+ protected AbstractNode(final IParserNode node) {
+ internalNode = node;
+ }
+
+ /**
+ * @return
+ */
+ public abstract AbstractNode compute();
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.INode#getInternalNode()
+ */
+ public IParserNode getInternalNode() {
+ return internalNode;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/impl/AttributeNode.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/impl/AttributeNode.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/impl/AttributeNode.java
new file mode 100644
index 0000000..41edcb3
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/impl/AttributeNode.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 org.apache.flex.pmd.nodes.impl;
+
+import org.apache.flex.pmd.nodes.IAttribute;
+import org.apache.flex.pmd.parser.IParserNode;
+
+/**
+ * @author xagnetti
+ */
+class AttributeNode extends FieldNode implements IAttribute {
+ /**
+ * @param rootNode
+ */
+ protected AttributeNode(final IParserNode rootNode) {
+ super(rootNode);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.impl.FieldNode#compute()
+ */
+ @Override
+ public AttributeNode compute() {
+ return (AttributeNode) super.compute();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/impl/ClassNode.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/impl/ClassNode.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/impl/ClassNode.java
new file mode 100644
index 0000000..796d374
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/impl/ClassNode.java
@@ -0,0 +1,340 @@
+/*
+ * 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 org.apache.flex.pmd.nodes.impl;
+
+import org.apache.flex.pmd.nodes.*;
+import org.apache.flex.pmd.parser.IParserNode;
+import org.apache.flex.pmd.parser.NodeKind;
+
+import java.util.*;
+import java.util.Map.Entry;
+
+/**
+ * @author xagnetti
+ */
+class ClassNode extends AbstractNode implements IClass {
+ private IParserNode asDoc;
+ private final List<IAttribute> attributes;
+ private IParserNode block;
+ private final List<IConstant> constants;
+ private IFunction constructor;
+ private String extensionName;
+ private final List<IFunction> functions;
+ private List<IParserNode> implementations;
+ private final Map<MetaData, List<IMetaData>> metaDataList;
+ private final Set<Modifier> modifiers;
+ private final List<IParserNode> multiLinesComments;
+ private IdentifierNode name;
+
+ /**
+ * @param node
+ */
+ protected ClassNode(final IParserNode node) {
+ super(node);
+
+ modifiers = new HashSet<Modifier>();
+ metaDataList = new LinkedHashMap<MetaData, List<IMetaData>>();
+ implementations = new ArrayList<IParserNode>();
+ constants = new ArrayList<IConstant>();
+ attributes = new ArrayList<IAttribute>();
+ functions = new ArrayList<IFunction>();
+ multiLinesComments = new ArrayList<IParserNode>();
+ name = null;
+ asDoc = null;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.nodes.IMetaDataListHolder#add(com.adobe.ac.pmd.nodes.
+ * IMetaData)
+ */
+ public void add(final IMetaData metaData) {
+ final MetaData metaDataImpl = MetaData.create(metaData.getName());
+
+ if (!metaDataList.containsKey(metaDataImpl)) {
+ metaDataList.put(metaDataImpl,
+ new ArrayList<IMetaData>());
+ }
+ metaDataList.get(metaDataImpl).add(metaData);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.nodes.IModifiersHolder#add(com.adobe.ac.pmd.nodes.Modifier
+ * )
+ */
+ public void add(final Modifier modifier) {
+ modifiers.add(modifier);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.impl.AbstractNode#compute()
+ */
+ @Override
+ public ClassNode compute() {
+ if (getInternalNode().numChildren() != 0) {
+ for (final IParserNode node : getInternalNode().getChildren()) {
+ if (node.is(NodeKind.CONTENT)) {
+ computeClassContent(node);
+ } else if (node.is(NodeKind.MOD_LIST)) {
+ computeModifierList(this,
+ node);
+ } else if (node.is(NodeKind.NAME)) {
+ name = IdentifierNode.create(node);
+ } else if (node.is(NodeKind.META_LIST)) {
+ computeMetaDataList(this,
+ node);
+ } else if (node.is(NodeKind.AS_DOC)) {
+ asDoc = node;
+ } else if (node.is(NodeKind.MULTI_LINE_COMMENT)) {
+ multiLinesComments.add(node);
+ }
+ detectImplementations(node);
+ detectExtensions(node);
+ }
+ for (final IFunction function : functions) {
+ if (name.toString().equals(function.getName())) {
+ constructor = function;
+ }
+ }
+ }
+ return this;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.IMetaDataListHolder#getAllMetaData()
+ */
+ public List<IMetaData> getAllMetaData() {
+ final List<IMetaData> list = new ArrayList<IMetaData>();
+
+ for (final Entry<MetaData, List<IMetaData>> entry : metaDataList.entrySet()) {
+ list.addAll(entry.getValue());
+ }
+
+ return list;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.IAsDocHolder#getAsDoc()
+ */
+ public IParserNode getAsDoc() {
+ return asDoc;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.IClass#getAttributes()
+ */
+ public List<IAttribute> getAttributes() {
+ return attributes;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.IClass#getAverageCyclomaticComplexity()
+ */
+ public double getAverageCyclomaticComplexity() {
+ if (functions.isEmpty()) {
+ return 0;
+ }
+ int totalCcn = 0;
+
+ for (final IFunction function : functions) {
+ totalCcn += function.getCyclomaticComplexity();
+ }
+
+ return totalCcn
+ / functions.size();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.IClass#getBlock()
+ */
+ public final IParserNode getBlock() {
+ return block;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.IClass#getConstants()
+ */
+ public List<IConstant> getConstants() {
+ return constants;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.IClass#getConstructor()
+ */
+ public IFunction getConstructor() {
+ return constructor;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.IClass#getExtensionName()
+ */
+ public String getExtensionName() {
+ return extensionName;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.IClass#getFunctions()
+ */
+ public List<IFunction> getFunctions() {
+ return functions;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.IClass#getImplementations()
+ */
+ public List<IParserNode> getImplementations() {
+ return implementations;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.nodes.IMetaDataListHolder#getMetaData(com.adobe.ac.pmd
+ * .nodes.MetaData)
+ */
+ public List<IMetaData> getMetaData(final MetaData metaDataName) {
+ if (metaDataList.containsKey(metaDataName)) {
+ return metaDataList.get(metaDataName);
+ } else {
+ return new ArrayList<IMetaData>();
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.IMetaDataListHolder#getMetaDataCount()
+ */
+ public int getMetaDataCount() {
+ return metaDataList.size();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.ICommentHolder#getMultiLinesComment()
+ */
+ public List<IParserNode> getMultiLinesComment() {
+ return multiLinesComments;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.INamable#getName()
+ */
+ public String getName() {
+ return name.toString();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.nodes.IModifiersHolder#is(com.adobe.ac.pmd.nodes.Modifier
+ * )
+ */
+ public boolean is(final Modifier modifier) // NOPMD
+ {
+ return modifiers.contains(modifier);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.IClass#isBindable()
+ */
+ public boolean isBindable() {
+ return metaDataList.get(MetaData.BINDABLE) != null;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.IClass#isFinal()
+ */
+ public boolean isFinal() {
+ return is(Modifier.FINAL);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.IVisible#isPublic()
+ */
+ public boolean isPublic() {
+ return is(Modifier.PUBLIC);
+ }
+
+ private void computeClassContent(final IParserNode classContentNode) {
+ if (classContentNode.numChildren() != 0) {
+ for (final IParserNode node : classContentNode.getChildren()) {
+ detectBlock(node);
+ detectFunction(node);
+ detectAttribute(node);
+ detectConstant(node);
+ if (node.is(NodeKind.MULTI_LINE_COMMENT)) {
+ multiLinesComments.add(node);
+ }
+ }
+ }
+ }
+
+ private void detectAttribute(final IParserNode node) {
+ if (node.is(NodeKind.VAR_LIST)) {
+ attributes.add(new AttributeNode(node).compute());
+ }
+ }
+
+ private void detectBlock(final IParserNode node) {
+ if (node.is(NodeKind.BLOCK)) {
+ block = node;
+ }
+ }
+
+ private void detectConstant(final IParserNode node) {
+ if (node.is(NodeKind.CONST_LIST)) {
+ constants.add(new ConstantNode(node).compute());
+ }
+ }
+
+ private void detectExtensions(final IParserNode node) {
+ if (node.is(NodeKind.EXTENDS)) {
+ extensionName = node.getStringValue();
+ }
+ }
+
+ private void detectFunction(final IParserNode node) {
+ if (node.is(NodeKind.FUNCTION)
+ || node.is(NodeKind.GET) || node.is(NodeKind.SET)) {
+ functions.add(new FunctionNode(node).compute());
+ }
+ }
+
+ private void detectImplementations(final IParserNode node) {
+ if (node.is(NodeKind.IMPLEMENTS_LIST)) {
+ implementations = node.getChildren();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/impl/ConstantNode.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/impl/ConstantNode.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/impl/ConstantNode.java
new file mode 100644
index 0000000..4aa2b68
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/impl/ConstantNode.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 org.apache.flex.pmd.nodes.impl;
+
+import org.apache.flex.pmd.nodes.IConstant;
+import org.apache.flex.pmd.parser.IParserNode;
+
+/**
+ * @author xagnetti
+ */
+class ConstantNode extends FieldNode implements IConstant {
+ /**
+ * @param rootNode
+ */
+ protected ConstantNode(final IParserNode rootNode) {
+ super(rootNode);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.impl.FieldNode#compute()
+ */
+ @Override
+ public ConstantNode compute() {
+ return (ConstantNode) super.compute();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/impl/FieldInitializationNode.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/impl/FieldInitializationNode.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/impl/FieldInitializationNode.java
new file mode 100644
index 0000000..5eb8abf
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/impl/FieldInitializationNode.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.flex.pmd.nodes.impl;
+
+import org.apache.flex.pmd.nodes.IFieldInitialization;
+import org.apache.flex.pmd.parser.IParserNode;
+
+/**
+ * @author xagnetti
+ */
+class FieldInitializationNode extends AbstractNode implements IFieldInitialization {
+ /**
+ * @param node
+ * @return
+ */
+ static FieldInitializationNode create(final IParserNode node) {
+ return new FieldInitializationNode(node);
+ }
+
+ /**
+ * @param node
+ */
+ protected FieldInitializationNode(final IParserNode node) {
+ super(node);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.impl.AbstractNode#compute()
+ */
+ @Override
+ public FieldInitializationNode compute() {
+ return this;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/impl/FieldNode.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/impl/FieldNode.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/impl/FieldNode.java
new file mode 100644
index 0000000..718585a
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/impl/FieldNode.java
@@ -0,0 +1,83 @@
+/*
+ * 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 org.apache.flex.pmd.nodes.impl;
+
+import org.apache.flex.pmd.nodes.IField;
+import org.apache.flex.pmd.nodes.Modifier;
+import org.apache.flex.pmd.parser.IParserNode;
+import org.apache.flex.pmd.parser.NodeKind;
+
+/**
+ * Base class for AttributeNode and for ConstantNode
+ *
+ * @author xagnetti
+ */
+class FieldNode extends VariableNode implements IField {
+ private IParserNode asDocs;
+
+ /**
+ * @param rootNode
+ */
+ protected FieldNode(final IParserNode rootNode) {
+ super(rootNode);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.impl.VariableNode#compute()
+ */
+ @Override
+ public FieldNode compute() {
+ super.compute();
+
+ if (getInternalNode().numChildren() != 0) {
+ for (final IParserNode child : getInternalNode().getChildren()) {
+ if (child.is(NodeKind.MOD_LIST)) {
+ computeModifierList(this,
+ child);
+ } else if (child.is(NodeKind.AS_DOC)) {
+ asDocs = child;
+ }
+ }
+ }
+ return this;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.IAsDocHolder#getAsDoc()
+ */
+ public IParserNode getAsDoc() {
+ return asDocs;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.IVisible#isPublic()
+ */
+ public boolean isPublic() {
+ return is(Modifier.PUBLIC);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.IField#isStatic()
+ */
+ public boolean isStatic() {
+ return is(Modifier.STATIC);
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/impl/FormalNode.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/impl/FormalNode.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/impl/FormalNode.java
new file mode 100644
index 0000000..c37b71f
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/nodes/impl/FormalNode.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.flex.pmd.nodes.impl;
+
+import org.apache.flex.pmd.nodes.IParameter;
+import org.apache.flex.pmd.parser.IParserNode;
+
+/**
+ * @author xagnetti
+ */
+final class FormalNode extends VariableNode implements IParameter {
+ /**
+ * @param node
+ * @return
+ */
+ static FormalNode create(final IParserNode node) {
+ return new FormalNode(node).compute();
+ }
+
+ /**
+ * @param node
+ */
+ private FormalNode(final IParserNode node) {
+ super(node);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.nodes.impl.VariableNode#compute()
+ */
+ @Override
+ public FormalNode compute() {
+ return (FormalNode) super.compute();
+ }
+}
[06/24] git commit: [flex-utilities]
[refs/heads/feature/pmd-5.2-language-module] - Initial commit of the PMD
language module for Apache Flex
Posted by cd...@apache.org.
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/style/ImportFromSamePackageRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/style/ImportFromSamePackageRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/style/ImportFromSamePackageRuleTest.java
new file mode 100644
index 0000000..640f680
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/style/ImportFromSamePackageRuleTest.java
@@ -0,0 +1,35 @@
+/*
+ * 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 org.apache.flex.pmd.rules.style;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class ImportFromSamePackageRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("com.adobe.ac.ncss.BigImporterModel.as", new ViolationPosition[]
+ {new ViolationPosition(21)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new ImportFromSamePackageRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/style/OverLongLineRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/style/OverLongLineRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/style/OverLongLineRuleTest.java
new file mode 100644
index 0000000..121da9f
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/style/OverLongLineRuleTest.java
@@ -0,0 +1,52 @@
+/*
+ * 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 org.apache.flex.pmd.rules.style;
+
+import org.apache.flex.pmd.rules.AbstractFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class OverLongLineRuleTest extends AbstractFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("RadonDataGrid.as", new ViolationPosition[]
+ {new ViolationPosition(56),
+ new ViolationPosition(72),
+ new ViolationPosition(105)}),
+ new ExpectedViolation("Simple.as", new ViolationPosition[]
+ {new ViolationPosition(1)}),
+/* new ExpectedViolation( "FileReferenceList.as", new ViolationPosition[]
+ { new ViolationPosition( 47 ) } ),
+*/ new ExpectedViolation("AbstractRowData.as", new ViolationPosition[]
+ {new ViolationPosition(34),
+ new ViolationPosition(35),
+ new ViolationPosition(37)}),
+ new ExpectedViolation("com.adobe.ac.ncss.BigImporterModel.as", new ViolationPosition[]
+ {new ViolationPosition(50)}),
+ new ExpectedViolation("SkinStyles.as", new ViolationPosition[]
+ {new ViolationPosition(60)}),
+ new ExpectedViolation("com.adobe.ac.ncss.mxml.IterationsList2.mxml",
+ new ViolationPosition[]
+ {new ViolationPosition(40)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new OverLongLineRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/style/TabUsedAsIndentorRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/style/TabUsedAsIndentorRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/style/TabUsedAsIndentorRuleTest.java
new file mode 100644
index 0000000..41241b9
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/style/TabUsedAsIndentorRuleTest.java
@@ -0,0 +1,86 @@
+/*
+ * 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 org.apache.flex.pmd.rules.style;
+
+import net.sourceforge.pmd.PMDException;
+import org.apache.flex.pmd.files.impl.FileUtils;
+import org.apache.flex.pmd.rules.AbstractRegExpBasedRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractRegexpBasedRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+import java.io.File;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.logging.Logger;
+
+public class TabUsedAsIndentorRuleTest extends AbstractRegExpBasedRuleTest {
+ private static final Logger LOGGER = Logger.getLogger(TabUsedAsIndentorRuleTest.class.getName());
+ private final String TEST_FOLDER = "/com/adobe/ac/ncss/event";
+
+ public TabUsedAsIndentorRuleTest() {
+ super();
+ final URL resource = this.getClass().getResource("/test"
+ + TEST_FOLDER);
+
+ if (resource != null) {
+ try {
+ setTestFiles(FileUtils.computeFilesList(new File(resource.toURI().getPath()),
+ null,
+ "",
+ null));
+ } catch (final PMDException e) {
+ LOGGER.warning(e.getLocalizedMessage());
+ } catch (final URISyntaxException e) {
+ LOGGER.warning(e.getLocalizedMessage());
+ }
+ }
+ }
+
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("SecondCustomEvent.as", new ViolationPosition[]
+ {new ViolationPosition(25)})};
+ }
+
+ @Override
+ protected String[] getMatchableLines() {
+ return new String[]
+ {"\t",
+ " \t\t",
+ " \t "};
+ }
+
+ @Override
+ protected AbstractRegexpBasedRule getRegexpBasedRule() {
+ return new TabUsedAsIndentorRule();
+ }
+
+ @Override
+ protected File getTestDirectory() // NO_UCD
+ {
+ return new File(super.getTestDirectory().getAbsolutePath()
+ + TEST_FOLDER);
+ }
+
+ @Override
+ protected String[] getUnmatchableLines() {
+ return new String[]
+ {" ",
+ "lala\t\t"};
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/switchrules/IdenticalSwitchCasesRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/switchrules/IdenticalSwitchCasesRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/switchrules/IdenticalSwitchCasesRuleTest.java
new file mode 100644
index 0000000..5fe8315
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/switchrules/IdenticalSwitchCasesRuleTest.java
@@ -0,0 +1,36 @@
+/*
+ * 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 org.apache.flex.pmd.rules.switchrules;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+import org.apache.flex.pmd.rules.switches.IdenticalSwitchCasesRule;
+
+public class IdenticalSwitchCasesRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("com.adobe.ac.ncss.LongSwitch.as", new ViolationPosition[]
+ {new ViolationPosition(46)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new IdenticalSwitchCasesRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/switchrules/NestedSwitchRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/switchrules/NestedSwitchRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/switchrules/NestedSwitchRuleTest.java
new file mode 100644
index 0000000..a45ca8e
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/switchrules/NestedSwitchRuleTest.java
@@ -0,0 +1,38 @@
+/*
+ * 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 org.apache.flex.pmd.rules.switchrules;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+import org.apache.flex.pmd.rules.switches.NestedSwitchRule;
+
+public class NestedSwitchRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("com.adobe.ac.ncss.LongSwitch.as", new ViolationPosition[]
+ {new ViolationPosition(41)}),
+ new ExpectedViolation("com.adobe.ac.ncss.NestedSwitch.as", new ViolationPosition[]
+ {new ViolationPosition(31)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new NestedSwitchRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/switchrules/NonBreakableSwitchCaseRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/switchrules/NonBreakableSwitchCaseRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/switchrules/NonBreakableSwitchCaseRuleTest.java
new file mode 100644
index 0000000..dc8bc34
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/switchrules/NonBreakableSwitchCaseRuleTest.java
@@ -0,0 +1,36 @@
+/*
+ * 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 org.apache.flex.pmd.rules.switchrules;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+import org.apache.flex.pmd.rules.switches.NonBreakableSwitchCaseRule;
+
+public class NonBreakableSwitchCaseRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("com.adobe.ac.ncss.LongSwitch.as", new ViolationPosition[]
+ {new ViolationPosition(122)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new NonBreakableSwitchCaseRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/switchrules/SwitchStatementsShouldHaveDefaultRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/switchrules/SwitchStatementsShouldHaveDefaultRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/switchrules/SwitchStatementsShouldHaveDefaultRuleTest.java
new file mode 100644
index 0000000..d1c1a02
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/switchrules/SwitchStatementsShouldHaveDefaultRuleTest.java
@@ -0,0 +1,40 @@
+/*
+ * 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 org.apache.flex.pmd.rules.switchrules;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+import org.apache.flex.pmd.rules.switches.SwitchStatementsShouldHaveDefaultRule;
+
+public class SwitchStatementsShouldHaveDefaultRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("com.adobe.ac.ncss.LongSwitch.as", new ViolationPosition[]
+ {new ViolationPosition(41),
+ new ViolationPosition(29),
+ new ViolationPosition(80)}),
+ new ExpectedViolation("com.adobe.ac.ncss.NestedSwitch.as", new ViolationPosition[]
+ {new ViolationPosition(31)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new SwitchStatementsShouldHaveDefaultRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/switchrules/TooFewBrancheInSwitchStatementRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/switchrules/TooFewBrancheInSwitchStatementRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/switchrules/TooFewBrancheInSwitchStatementRuleTest.java
new file mode 100644
index 0000000..04ac50e
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/switchrules/TooFewBrancheInSwitchStatementRuleTest.java
@@ -0,0 +1,38 @@
+/*
+ * 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 org.apache.flex.pmd.rules.switchrules;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+import org.apache.flex.pmd.rules.switches.TooFewBrancheInSwitchStatementRule;
+
+public class TooFewBrancheInSwitchStatementRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("com.adobe.ac.ncss.LongSwitch.as", new ViolationPosition[]
+ {new ViolationPosition(41)}),
+ new ExpectedViolation("com.adobe.ac.ncss.NestedSwitch.as", new ViolationPosition[]
+ {new ViolationPosition(31)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new TooFewBrancheInSwitchStatementRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/unused/EmptyPrivateMethodRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/unused/EmptyPrivateMethodRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/unused/EmptyPrivateMethodRuleTest.java
new file mode 100644
index 0000000..885c455
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/unused/EmptyPrivateMethodRuleTest.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 org.apache.flex.pmd.rules.unused;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class EmptyPrivateMethodRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("bug.FlexPMD97.as", new ViolationPosition[]
+ {new ViolationPosition(27)}),
+ new ExpectedViolation("Sorted.as", new ViolationPosition[]
+ {new ViolationPosition(50),
+ new ViolationPosition(59)}),
+ new ExpectedViolation("com.adobe.ac.ncss.BigModel.as", new ViolationPosition[]
+ {new ViolationPosition(70),
+ new ViolationPosition(74),
+ new ViolationPosition(78),
+ new ViolationPosition(82),
+ new ViolationPosition(86)}),
+ new ExpectedViolation("cairngorm.events.CorrectConstantEvent.as", new ViolationPosition[]
+ {new ViolationPosition(41)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new EmptyPrivateMethodRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/unused/UnusedFieldRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/unused/UnusedFieldRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/unused/UnusedFieldRuleTest.java
new file mode 100644
index 0000000..ebdce01
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/unused/UnusedFieldRuleTest.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 org.apache.flex.pmd.rules.unused;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class UnusedFieldRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("Responder.as", new ViolationPosition[]
+ {new ViolationPosition(25)}),
+ new ExpectedViolation("Sorted.as", new ViolationPosition[]
+ {new ViolationPosition(42)}),
+ new ExpectedViolation("com.adobe.ac.ncss.BigModel.as", new ViolationPosition[]
+ {new ViolationPosition(30)}),
+ new ExpectedViolation("Title.as", new ViolationPosition[]
+ {new ViolationPosition(29)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new UnusedFieldRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/unused/UnusedLocalVariableRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/unused/UnusedLocalVariableRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/unused/UnusedLocalVariableRuleTest.java
new file mode 100644
index 0000000..4ed6a02
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/unused/UnusedLocalVariableRuleTest.java
@@ -0,0 +1,83 @@
+/*
+ * 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 org.apache.flex.pmd.rules.unused;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+import org.testng.annotations.Test;
+
+@Test(enabled = false) // This test requires test-data that was not donated to Apache
+public class UnusedLocalVariableRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("src.epg.StateExit_AS2.as", new ViolationPosition[]
+ {new ViolationPosition(62),
+ new ViolationPosition(63),
+ new ViolationPosition(67),
+ new ViolationPosition(68),
+ new ViolationPosition(69),
+ new ViolationPosition(70),
+ new ViolationPosition(71),
+ new ViolationPosition(72),
+ new ViolationPosition(73),
+ new ViolationPosition(74),
+ new ViolationPosition(75),
+ new ViolationPosition(76),
+ new ViolationPosition(77)}),
+ new ExpectedViolation("DeleteButtonRenderer.mxml", new ViolationPosition[]
+ {new ViolationPosition(69)}),
+ new ExpectedViolation("com.adobe.ac.ncss.VoidConstructor.as", new ViolationPosition[]
+ {new ViolationPosition(40)}),
+ new ExpectedViolation("RadonDataGrid.as", new ViolationPosition[]
+ {new ViolationPosition(100),
+ new ViolationPosition(101)}),
+ new ExpectedViolation("com.adobe.ac.ncss.BigModel.as", new ViolationPosition[]
+ {new ViolationPosition(47)}),
+ new ExpectedViolation("UnboundMetadata.as", new ViolationPosition[]
+ {new ViolationPosition(50)}),
+ new ExpectedViolation("com.adobe.ac.ncss.BigImporterModel.as", new ViolationPosition[]
+ {new ViolationPosition(64)}),
+ new ExpectedViolation("GenericType.as", new ViolationPosition[]
+ {new ViolationPosition(46)}),
+ new ExpectedViolation("ErrorToltipSkin.as", new ViolationPosition[]
+ {new ViolationPosition(163),
+ new ViolationPosition(165),
+ new ViolationPosition(166),
+ new ViolationPosition(183),
+ new ViolationPosition(184)}),
+ new ExpectedViolation("bug.Duane.mxml", new ViolationPosition[]
+ {new ViolationPosition(68)}),
+ new ExpectedViolation("bug.FlexPMD88.as", new ViolationPosition[]
+ {new ViolationPosition(42),
+ new ViolationPosition(43),
+ new ViolationPosition(44),
+ new ViolationPosition(45)}),
+ new ExpectedViolation("flexpmd114.a.Test.as", new ViolationPosition[]
+ {new ViolationPosition(42)}),
+ new ExpectedViolation("flexpmd114.b.Test.as", new ViolationPosition[]
+ {new ViolationPosition(42)}),
+ new ExpectedViolation("flexpmd114.c.Test.as", new ViolationPosition[]
+ {new ViolationPosition(42)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new UnusedLocalVariableRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/unused/UnusedParameterRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/unused/UnusedParameterRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/unused/UnusedParameterRuleTest.java
new file mode 100644
index 0000000..31e5a07
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/unused/UnusedParameterRuleTest.java
@@ -0,0 +1,52 @@
+/*
+ * 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 org.apache.flex.pmd.rules.unused;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+import org.testng.annotations.Test;
+
+import java.util.LinkedHashMap;
+
+@Test(enabled = false) // This test requires test-data that was not donated to Apache
+public class UnusedParameterRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ new LinkedHashMap<String, ViolationPosition[]>();
+
+ return new ExpectedViolation[]
+ {new ExpectedViolation("FileReferenceList.as", new ViolationPosition[]
+ {new ViolationPosition(70)}),
+ new ExpectedViolation("cairngorm.NonBindableModelLocator.as", new ViolationPosition[]
+ {new ViolationPosition(43)}),
+ new ExpectedViolation("bug.FlexPMD232.as", new ViolationPosition[]
+ {new ViolationPosition(35),
+ new ViolationPosition(35)}),
+ new ExpectedViolation("com.adobe.ac.ncss.BigImporterModel.as", new ViolationPosition[]
+ {new ViolationPosition(62),
+ new ViolationPosition(62),
+ new ViolationPosition(62)}),
+ new ExpectedViolation("Sorted.as", new ViolationPosition[]
+ {new ViolationPosition(67)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new UnusedParameterRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/unused/UnusedPrivateMethodRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/unused/UnusedPrivateMethodRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/unused/UnusedPrivateMethodRuleTest.java
new file mode 100644
index 0000000..5eaac66
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/unused/UnusedPrivateMethodRuleTest.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 org.apache.flex.pmd.rules.unused;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class UnusedPrivateMethodRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("bug.Duane.mxml", new ViolationPosition[]
+ {new ViolationPosition(52)}),
+ new ExpectedViolation("Sorted.as", new ViolationPosition[]
+ {new ViolationPosition(59)}),
+ new ExpectedViolation("cairngorm.LightController.as", new ViolationPosition[]
+ {new ViolationPosition(179)}),
+ new ExpectedViolation("RadonDataGrid.as", new ViolationPosition[]
+ {new ViolationPosition(195)}),
+ new ExpectedViolation("com.adobe.ac.ncss.BigModel.as", new ViolationPosition[]
+ {new ViolationPosition(74),
+ new ViolationPosition(78),
+ new ViolationPosition(82),
+ new ViolationPosition(86)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new UnusedPrivateMethodRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/AbstractRowData.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/AbstractRowData.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/AbstractRowData.as
new file mode 100644
index 0000000..bbf54ce
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/AbstractRowData.as
@@ -0,0 +1,136 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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 flexUnit.flexui.data
+{
+ import flexunit.flexui.controls.FlexUnitLabelsModelLocator;
+
+ import mx.binding.utils.ChangeWatcher;
+ import mx.formatters.NumberFormatter;
+
+ /**
+ * Abstract class representing a row in the test cases tree.
+ * A row can be either a test class (node) or a test case (leaf)
+ */
+ final public class AbstractRowData
+ {
+ protected var logger : ILogger;
+ public const logger : ILogger;
+ public const logger : ILogger = Log.getLogger( "flexUnit.flexui.data.AbstractRowData" );
+ public const LOGGER : ILogger = Log.getLogger( "flexUnit.flexui.data.AbstractRowData" );
+ public const LOG : ILogger = Log.getLogger( "flexUnit.AbstractRowData" );
+ public static const LOG : ILogger = Log.getLogger( "flexUnit.flexui.data.AbstractRowData" );
+ public const LOG : ILogger = Log.getLogger( "flexUnit.flexui.data.AbstractRowData" );
+ // public var testIsFailure : Boolean;
+ public var objectUse : Object;
+
+ /**
+ * @return the class name from the qualified class name
+ */
+ /*public function get className() : String
+ {
+ if ( qualifiedClassName )
+ {
+ var splitIndex : int = qualifiedClassName.lastIndexOf( "::" );
+
+ if ( splitIndex >= 0 )
+ {
+ return qualifiedClassName.substring( splitIndex + 2 );
+ }
+ }
+
+ return qualifiedClassName;
+ }*/
+
+ /**
+ * Abstract method. Defined in TestCaseRowData and in TestClassRowData
+ *
+ * @return the count of assertions which have been made either in average if
+ * the current row is a test class or in total if the current row is a test case
+ */
+ // One line comment
+ public function get assertionsMade() : Number
+ {
+ throw new Error( "TestSummaryRowData::assertionsMade is an abstract method" );
+ }
+
+ public function get failIcon() : Class
+ {
+ throw new Error( "TestSummaryRowData::failIcon is an abstract method" );
+ }
+
+ protected function get passIcon() : Class
+ {
+ throw new Error( "TestSummaryRowData::passIcon is an abstract method" );
+ }
+
+ /**
+ * Abstract method which allows the legend to be correctly formatted.
+ *
+ * @return true for the TestClassRowData and false for the TestCaseRowData
+ */
+ public function get isAverage() : Boolean
+ {
+ throw new Error( "TestSummaryRowData::isAverage is an abstract method" );
+ }
+
+ public function get formattedAssertionsMade() : String
+ {
+ if(true)
+ {
+ }
+ addEventListener("lalaEvent");
+ CairngormEventDispatcher.getInstance().dispatchEvent(new Event("lalaEvent"));
+ dispatchEvent( new Event( "lalaEvent" ) );
+ dispatchEvent( new Event( EVENT ) );
+ if( true );
+ CairngormEventDispatcher.getInstance().addEventListener(CONSTANT, onHearing);
+ return f.format( assertionsMade );
+ }
+
+ /**
+ * @return the correcly formatted (no typos) legend for the number of assertions
+ * made.
+ *
+ * Can return :
+ * - 0 assertions have been made in average
+ * - 0 assertions have been made in total
+ * - 1 assertion has been made in average
+ * - 1 assertion has been made in total
+ * - 2 assertions have been made in average
+ * - 2 assertions have been made in total
+ */
+ public function get assertionsMadeLegend() : String
+ {
+ return FlexUnitLabels.formatAssertions(
+ formattedAssertionsMade,
+ assertionsMade,
+ isAverage );
+ }
+
+ override protected function createChildren() : void
+ {
+ super.createChildren();
+ }
+
+ override protected function updateDisplayList( width : int, height : int ) : void
+ {
+ super.updateDisplayList( width * 2, height );
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/AbstractRowData.mxml
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/AbstractRowData.mxml b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/AbstractRowData.mxml
new file mode 100644
index 0000000..c31373b
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/AbstractRowData.mxml
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+
+ 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.
+
+-->
+<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
+ xmlns="*">
+
+ <mx:Script>
+ <![CDATA[
+ public override function closePopup() : void
+ {
+ if ( useWithPopUpWrapper )
+ {
+ dispatchEvent( new Event( CLOSE_POPUP_EVENT ) );
+ } else
+ {
+ super.closePopup( event );
+ }
+ }
+ ]]>
+ </mx:Script>
+
+ <mx:Script>
+ <![CDATA[
+
+ ]]>
+ </mx:Script>
+
+</mx:Application>
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/BadComponent.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/BadComponent.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/BadComponent.as
new file mode 100644
index 0000000..f45be51
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/BadComponent.as
@@ -0,0 +1,43 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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.view
+{
+ import mx.controls.Label;
+ import mx.core.UIComponent;
+
+ public class BadComponent extends UIComponent
+ {
+ override protected function updateDisplayList( w : Number, h : Number ) : void
+ {
+ super.updateDisplayList( w, h );
+
+ addChild( new Label() );
+ addChildAt( new Label() );
+ removeChild( new Label() );
+ removeChildAt( 0 );
+ }
+
+ override protected function createChildren() : void
+ {
+ super.createChildren();
+
+ addMyChildren();
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/Color.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/Color.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/Color.as
new file mode 100644
index 0000000..aec4604
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/Color.as
@@ -0,0 +1,29 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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 org.colors
+
+{
+
+ public interface Color
+
+ {
+ function foo() : void;
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/DefaultNameEvent.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/DefaultNameEvent.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/DefaultNameEvent.as
new file mode 100644
index 0000000..6d95245
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/DefaultNameEvent.as
@@ -0,0 +1,36 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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
+{
+ public class DefaultNameEvent extends Event
+ {
+ public static const DAY_CHANGE : String = "dayChange";
+ public static const DELAYED_MIDNIGHT_REFRESH : String = "delayedMidnightRefresh";
+
+ public function DefaultNameEvent( type : String = "" )
+ {
+ super( type );
+ }
+
+ override public function clone() : Event
+ {
+ return new DefaultNameEvent( type );
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/DeleteButtonRenderer.mxml
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/DeleteButtonRenderer.mxml b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/DeleteButtonRenderer.mxml
new file mode 100644
index 0000000..ea6dfd4
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/DeleteButtonRenderer.mxml
@@ -0,0 +1,101 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+
+ 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.
+
+-->
+<mx:Button xmlns:mx="http://www.adobe.com/2006/mxml"
+ icon="@Embed(source='/assets/icon_tool_trash2.png')"
+ toolTip="Remove this rule ({ rule.shortName }) from your ruleset..."
+ skin="mx.skins.ProgrammaticSkin"
+ buttonMode="true"
+ click="onClick()"
+ mouseChildren="false"
+ useHandCursor="true"
+ >
+
+ <mx:Metadata>
+ [Event(name="ruleRemoved", type="flash.events.Event")]
+ </mx:Metadata>
+
+ <mx:Script>
+ <![CDATA[
+ import com.adobe.ac.pmd.model.Rule;
+
+ import mx.controls.AdvancedDataGrid;
+ import mx.controls.listClasses.ListBase;
+ import mx.events.FlexEvent;
+ import mx.events.ListEvent;
+
+ public static const RULE_REMOVED : String = "ruleRemoved";
+
+ [Bindable]
+ private var rule : Rule;
+
+ private var grid : AdvancedDataGrid;
+
+ override public function set data( value : Object ) : void
+ {
+ super.data = value;
+
+ rule = value as Rule;
+ var ith : int = -1 + +1 + ith++ + -- ith;
+ if ( grid )
+ {
+ changeVisibility();
+ }
+ }
+
+ override protected function commitProperties() : void
+ {
+ super.commitProperties();
+
+ grid = AdvancedDataGrid( owner );
+ visible = false;
+ grid.addEventListener( ListEvent.CHANGE, onChange );
+ }
+
+ private function changeVisibility() : void
+ {
+ visible = grid.isItemSelected( data ) && rule != null;
+ }
+
+ private function onChange( event : ListEvent ) : void
+ {
+ changeVisibility();
+ }
+
+ private function onClick() : void
+ {
+ if ( rule )
+ {
+ rule.remove();
+
+ dispatchEvent( new Event( RULE_REMOVED, true ) );
+ }
+ }
+ ]]>
+ </mx:Script>
+
+ <mx:states>
+ <mx:State/>
+ <mx:State/>
+ <mx:State/>
+ <mx:State/>
+ <mx:State/>
+ </mx:states>
+
+</mx:Button>
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/ErrorToltipSkin.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/ErrorToltipSkin.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/ErrorToltipSkin.as
new file mode 100644
index 0000000..e15d298
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/ErrorToltipSkin.as
@@ -0,0 +1,317 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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.radon.core.skin
+{
+
+ import flash.display.GradientType;
+ import flash.display.Graphics;
+ import flash.display.InterpolationMethod;
+ import flash.display.SpreadMethod;
+ import flash.filters.DropShadowFilter;
+ import flash.geom.Matrix;
+
+ import mx.core.EdgeMetrics;
+ import mx.graphics.RectangularDropShadow;
+ import mx.skins.RectangularBorder;
+
+ /**
+ * The skin for a ToolTip.
+ */
+ public class ErrorToolTipSkin extends RectangularBorder
+ {
+ //--------------------------------------------------------------------------
+ //
+ // Constructor
+ //
+ //--------------------------------------------------------------------------
+
+ /**
+ * Constructor.
+ */
+ public function ErrorToolTipSkin()
+ {
+ super();
+ }
+
+ //--------------------------------------------------------------------------
+ //
+ // Variables
+ //
+ //--------------------------------------------------------------------------
+
+ /**
+ * @private
+ */
+ private var dropShadow:RectangularDropShadow;
+
+ //--------------------------------------------------------------------------
+ //
+ // Overridden properties
+ //
+ //--------------------------------------------------------------------------
+
+ //----------------------------------
+ // borderMetrics
+ //----------------------------------
+
+ /**
+ * @private
+ * Storage for the borderMetrics property.
+ */
+ private var _borderMetrics:EdgeMetrics;
+
+ /**
+ * @private
+ */
+ override public function get borderMetrics():EdgeMetrics
+ {
+ if (_borderMetrics)
+ return _borderMetrics;
+
+ var borderStyle:String = getStyle("borderStyle");
+ switch (borderStyle)
+ {
+ case "errorTipRight":
+ {
+ _borderMetrics = new EdgeMetrics(15, 1, 3, 3);
+ break;
+ }
+
+ case "errorTipAbove":
+ {
+ _borderMetrics = new EdgeMetrics(3, 1, 3, 15);
+ break;
+ }
+
+ case "errorTipBelow":
+ {
+ _borderMetrics = new EdgeMetrics(3, 13, 3, 3);
+ break;
+ }
+
+ default: // "toolTip"
+ {
+ _borderMetrics = new EdgeMetrics(3, 1, 3, 3);
+ break;
+ }
+ }
+
+ return _borderMetrics;
+ }
+
+ //--------------------------------------------------------------------------
+ //
+ // Overridden methods
+ //
+ //--------------------------------------------------------------------------
+
+ /**
+ * @private
+ * If borderStyle may have changed, clear the cached border metrics.
+ */
+ override public function styleChanged(styleProp:String):void
+ {
+ if (styleProp == "borderStyle" ||
+ styleProp == "styleName" ||
+ styleProp == null)
+ {
+ _borderMetrics = null;
+ }
+
+ invalidateDisplayList();
+ }
+
+ /**
+ * @private
+ * Draw the background and border.
+ */
+ override protected function updateDisplayList(w:Number, h:Number):void
+ {
+ super.updateDisplayList(w, h);
+
+ var borderStyle:String = getStyle("borderStyle");
+ var backgroundColor:uint = getStyle("backgroundColor");
+ var backgroundAlpha:Number= getStyle("backgroundAlpha");
+ var borderColor:uint = getStyle("borderColor");
+ var cornerRadius:Number = getStyle("cornerRadius");
+ var shadowColor:uint = getStyle("shadowColor");
+ var shadowAlpha:Number = 0.1;
+
+ var graphics:Graphics = graphics;
+ graphics.clear();
+
+ filters = [];
+
+ var type:String = GradientType.LINEAR;
+ var colors:Array = [0xff8300, 0xff4200];
+ var alphas:Array = [1, 1];
+ var ratios:Array = [0, 125 ];
+ var spreadMethod:String = SpreadMethod.PAD;
+ var interp:String = InterpolationMethod.RGB;
+ var focalPtRatio:Number = 0;
+
+ var matrix:Matrix = new Matrix();
+ var boxRotation:Number = Math.PI/2; // 90Ëš
+ var txx:Number = 0;
+ var tyy:Number = 0;
+
+ switch (borderStyle)
+ {
+ case "toolTip":
+ {
+ // face
+ drawRoundRect(
+ 3, 1, w - 6, h - 4, cornerRadius,
+ backgroundColor, backgroundAlpha)
+
+ if (!dropShadow)
+ dropShadow = new RectangularDropShadow();
+
+ dropShadow.distance = 3;
+ dropShadow.angle = 90;
+ dropShadow.color = 0;
+ dropShadow.alpha = 0.4;
+
+ dropShadow.tlRadius = cornerRadius + 2;
+ dropShadow.trRadius = cornerRadius + 2;
+ dropShadow.blRadius = cornerRadius + 2;
+ dropShadow.brRadius = cornerRadius + 2;
+
+ dropShadow.drawShadow(graphics, 3, 0, w - 6, h - 4);
+
+ break;
+ }
+
+ case "errorTipRight":
+ {
+ // border
+ matrix.createGradientBox(w - 11, h - 2, boxRotation, tx, ty);
+ graphics.beginGradientFill(
+ type,
+ colors,
+ alphas,
+ ratios,
+ matrix,
+ spreadMethod,
+ interp,
+ focalPtRatio);
+
+ drawRoundRect(
+ 11, 0, w - 11, h - 2, 0 );
+
+ // left pointer
+ graphics.beginGradientFill(
+ type,
+ colors,
+ alphas,
+ ratios,
+ matrix,
+ spreadMethod,
+ interp,
+ focalPtRatio);
+
+ graphics.moveTo(11, 7);
+ graphics.lineTo(0, 13);
+ graphics.lineTo(11, 19);
+ graphics.moveTo(11, 7);
+ graphics.endFill();
+
+ filters = [ new DropShadowFilter(2, 90, 0, 0.4) ];
+ break;
+ }
+
+ case "errorTipAbove":
+ {
+ // border
+ matrix.createGradientBox(w, h - 13, boxRotation, tx, ty);
+ graphics.beginGradientFill(
+ type,
+ colors,
+ alphas,
+ ratios,
+ matrix,
+ spreadMethod,
+ interp,
+ focalPtRatio);
+
+ drawRoundRect(
+ 0, 0, w, h - 13, 0 );
+
+ // bottom pointer
+ graphics.beginGradientFill(
+ type,
+ colors,
+ alphas,
+ ratios,
+ matrix,
+ spreadMethod,
+ interp,
+ focalPtRatio);
+
+ graphics.moveTo(9, h - 13);
+ graphics.lineTo(15, h - 2);
+ graphics.lineTo(21, h - 13);
+ graphics.moveTo(9, h - 13);
+ graphics.endFill();
+
+ filters = [ new DropShadowFilter(2, 90, 0, 0.4) ];
+ break;
+ }
+
+ case "errorTipBelow":
+ {
+ // border
+ matrix.createGradientBox(w, h - 13, boxRotation, tx, ty);
+ graphics.beginGradientFill(
+ type,
+ colors,
+ alphas,
+ ratios,
+ matrix,
+ spreadMethod,
+ interp,
+ focalPtRatio);
+
+ drawRoundRect(
+ 0, 11, w, h - 13, 0 );
+
+ // top pointer
+ graphics.beginGradientFill(
+ type,
+ colors,
+ alphas,
+ ratios,
+ matrix,
+ spreadMethod,
+ interp,
+ focalPtRatio);
+
+ graphics.moveTo(9, 11);
+ graphics.lineTo(15, 0);
+ graphics.lineTo(21, 11);
+ graphics.moveTo(10, 11);
+ graphics.endFill();
+
+ filters = [ new DropShadowFilter(2, 90, 0, 0.4) ];
+ break;
+ }
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/GenericType.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/GenericType.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/GenericType.as
new file mode 100644
index 0000000..94d42f5
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/GenericType.as
@@ -0,0 +1,37 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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 flexUnit.flexui.data
+{
+ public class GenericType extends com.adobe.ac.GenericType
+ {
+ public var logger : *;
+ public const logger : *;
+ public static const LOG : * = Log.getLogger( "flexUnit.flexui.data.AbstractRowData" );
+
+ public function get assertionsMade() : *
+ {
+ callLater( assertionsMadeLegend, [ null ] );
+ }
+
+ public override function set assertionsMadeLegend( fooBar : * ) : void
+ {
+ var tmp : * = new Object();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/GoodComponent.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/GoodComponent.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/GoodComponent.as
new file mode 100644
index 0000000..520cb20
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/GoodComponent.as
@@ -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.view
+{
+ import mx.controls.Label;
+ import mx.core.UIComponent;
+
+ public class GoodComponent extends UIComponent
+ {
+ override protected function updateDisplayList( w : Number, h : Number ) : void
+ {
+ super.updateDisplayList( w, h );
+ }
+
+ override protected function createChildren() : void
+ {
+ super.createChildren();
+
+ addChild( new Label() );
+ addChildAt( new Label() );
+ removeChild( new Label() );
+ removeChildAt( 0 );
+
+ var myDirect : MyObject;
+
+ with( myDirect )
+ {
+ i = "";
+ }
+ StyleManaer.loadStyles( something, false );
+ StyleManager.loadStyles( something );
+ StyleManager.loadStyles( something, true );
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/LinkButtonExample_Exception.mxml
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/LinkButtonExample_Exception.mxml b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/LinkButtonExample_Exception.mxml
new file mode 100644
index 0000000..67509df
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/LinkButtonExample_Exception.mxml
@@ -0,0 +1,38 @@
+<?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.
+
+-->
+<!-- Simple example to demonstrate the LinkButton control. -->
+<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
+
+ <mx:Script>
+ import mx.controls.Alert;
+ </mx:Script>
+
+ <mx:Panel title="LinkButton Control Example"
+ height="75%" width="75%" horizontalAlign="center"
+ paddingTop="10" paddingBottom="10" paddingLeft="10" paddingRight="10">
+
+ <mx:Label width="100%"
+ text="Select the LinkButton control to open the Alert control."/>
+
+ <mx:LinkButton label="LinkButton control" color="#0000FF" fontWeight="bold"
+ click="Alert.show('LinkButton selected!');"/>
+
+ </mx:Panel>
+</mx:Application>
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/Looping.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/Looping.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/Looping.as
new file mode 100644
index 0000000..75161a9
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/Looping.as
@@ -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
+{
+ import com.model.VO.ConfigVO;
+
+ import de.polygonal.ds.HashMap;
+
+ public class Looping
+ {
+ public function Looping()
+ {
+ for ( var i : int = 0; i < 10; i++ )
+ {
+ new Foo();
+ while( true )
+ {
+ new Object();
+ }
+ for each ( var i : Object in list )
+ {
+ new Object();
+ }
+ }
+ new Object();
+ for each ( var i : Object in list )
+ {
+ new Foo();
+ while( true )
+ {
+ new Object();
+ }
+ for each ( var i : Object in list )
+ {
+ var o : Object = new Object();
+ }
+ }
+ while( true )
+ {
+ new Foo();
+ while( true )
+ {
+ new Object();
+ }
+ for each ( var i : Object in list )
+ {
+ new Object();
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/Main.mxml
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/Main.mxml b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/Main.mxml
new file mode 100644
index 0000000..119e4c9
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/Main.mxml
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+
+ 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.
+
+-->
+<mx:Application xmlns:lcds="com.adobe.ac.lcds.*"
+ xmlns:mx="http://www.adobe.com/2006/mxml"
+ creationPolicy="all"
+ backgroundColor="#E57000"
+ horizontalAlign="left"
+ creationComplete="ds.fill(products, 'all')"
+ addedToStage="callLater( myFunction )"
+ xmlns="*">
+
+ <mx:Script>
+ <![CDATA[
+ import mx.data.mxml.DataService;
+ import mx.data.events.DataConflictEvent;
+ import mx.data.Conflicts;
+ import mx.data.Conflict;
+ ]]>
+ </mx:Script>
+
+ <mx:Style>
+.myStyle
+{
+}
+ </mx:Style>
+
+ <mx:Script source="myCodeBehind.as"/>
+</mx:Application>
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/MainWithModelLocator.mxml
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/MainWithModelLocator.mxml b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/MainWithModelLocator.mxml
new file mode 100644
index 0000000..dbf8840
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/MainWithModelLocator.mxml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+
+ 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.
+
+-->
+<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*"
+ backgroundColor="#E57000" horizontalAlign="left"
+ creationComplete="ds.fill(products, 'all')" xmlns:lcds="com.adobe.ac.lcds.*">
+
+ <mx:Script>
+ <![CDATA[
+ import mx.data.mxml.DataService;
+
+ import com.adobe.ac.MyModelLocator;
+ import mx.data.events.DataConflictEvent;
+ import mx.data.Conflicts;
+ import mx.data.Conflict;
+ import mx.controls.Alert;
+ ]]>
+ </mx:Script>
+
+ <mx:Style source="my.css"/>
+
+ <mx:Style
+ source="my.css"
+ />
+
+</mx:Application>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/MainWithNoCopyright.mxml
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/MainWithNoCopyright.mxml b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/MainWithNoCopyright.mxml
new file mode 100644
index 0000000..54ad461
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/MainWithNoCopyright.mxml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*"
+ >
+</mx:Application>
\ No newline at end of file
[03/24] git commit: [flex-utilities]
[refs/heads/feature/pmd-5.2-language-module] - Initial commit of the PMD
language module for Apache Flex
Posted by cd...@apache.org.
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/FlexPMD233b.mxml
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/FlexPMD233b.mxml b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/FlexPMD233b.mxml
new file mode 100644
index 0000000..a06fc62
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/FlexPMD233b.mxml
@@ -0,0 +1,300 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+
+ 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.
+
+-->
+<!--- The default skin class for a Spark TitleWindow container.
+
+@see spark.skins.spark.TitleWindowCloseButtonSkin
+@see spark.components.TitleWindow
+
+@langversion 3.0
+@playerversion Flash 10
+@playerversion AIR 1.5
+@productversion Flex 4
+-->
+<s:SparkSkin xmlns:fx="http://ns.adobe.com/mxml/2009"
+ xmlns:s="library://ns.adobe.com/flex/spark"
+ xmlns:fb="http://ns.adobe.com/flashbuilder/2009"
+ blendMode="normal"
+ mouseEnabled="false"
+ minWidth="76"
+ minHeight="76"
+ alpha.disabled="0.5"
+ alpha.disabledWithControlBar="0.5">
+
+ <fx:Metadata>
+ <![CDATA[
+ /**
+ * @copy spark.skins.spark.ApplicationSkin#hostComponent
+ */
+ [HostComponent("spark.components.TitleWindow")]
+ ]]>
+ </fx:Metadata>
+
+ <fx:Script fb:purpose="styling">
+ /* Define the skin elements that should not be colorized.
+ For panel, border and title background are skinned, but the content area and title text are not. */
+ static private const exclusions:Array = ["titleDisplay", "contentGroup"];// "background",
+
+ /**
+ * @private
+ */
+ override public function get colorizeExclusions():Array {return exclusions;}
+
+ /**
+ * @private
+ */
+ override protected function initializationComplete():void
+ {
+ useChromeColor = true;
+ super.initializationComplete();
+ }
+
+ /**
+ * @private
+ */
+ override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
+ {
+ if (getStyle("borderVisible") == true)
+ {
+ border.visible = true;
+ background.left = background.top = background.right = background.bottom = 1;
+ contents.left = contents.top = contents.right = contents.bottom = 1;
+ }
+ else
+ {
+ border.visible = false;
+ background.left = background.top = background.right = background.bottom = 0;
+ contents.left = contents.top = contents.right = contents.bottom = 0;
+ }
+
+ dropShadow.visible = getStyle("dropShadowVisible");
+
+ var cr:Number = getStyle("cornerRadius");
+ var withControls:Boolean =
+ (currentState == "disabledWithControlBar" ||
+ currentState == "normalWithControlBar" ||
+ currentState == "inactiveWithControlBar");
+
+ if (cornerRadius != cr)
+ {
+ cornerRadius = cr;
+
+ dropShadow.tlRadius = cornerRadius;
+ dropShadow.trRadius = cornerRadius;
+ dropShadow.blRadius = withControls ? cornerRadius : 0;
+ dropShadow.brRadius = withControls ? cornerRadius : 0;
+
+ setPartCornerRadii(topMaskRect, withControls);
+ setPartCornerRadii(border, withControls);
+ setPartCornerRadii(background, withControls);
+ }
+
+ if (bottomMaskRect) setPartCornerRadii(bottomMaskRect, withControls);
+
+ borderStroke.color = getStyle("borderColor");
+ borderStroke.alpha = getStyle("borderAlpha");
+ backgroundFill.color = getStyle("backgroundColor");
+ backgroundFill.alpha = getStyle("backgroundAlpha");
+
+ super.updateDisplayList(unscaledWidth, unscaledHeight);
+ }
+
+ /**
+ * @private
+ */
+ private function setPartCornerRadii(target:Rect, includeBottom:Boolean):void
+ {
+ target.topLeftRadiusX = cornerRadius;
+ target.topRightRadiusX = cornerRadius;
+ target.bottomLeftRadiusX = includeBottom ? cornerRadius : 0;
+ target.bottomRightRadiusX = includeBottom ? cornerRadius : 0;
+ }
+
+ private var cornerRadius:Number;
+ </fx:Script>
+
+ <s:states>
+ <s:State name="normal" />
+ <s:State name="inactive" stateGroups="inactiveGroup" />
+ <s:State name="disabled" />
+ <s:State name="normalWithControlBar" stateGroups="withControls" />
+ <s:State name="inactiveWithControlBar" stateGroups="withControls, inactiveGroup" />
+ <s:State name="disabledWithControlBar" stateGroups="withControls" />
+ </s:states>
+
+ <!--- drop shadow can't be hittable so it stays sibling of other graphics @private-->
+ <s:RectangularDropShadow id="dropShadow" blurX="20" blurY="20" alpha="0.32"
+ alpha.inactiveGroup="0.22" distance="11" distance.inactiveGroup="7"
+ angle="90" color="0x000000" left="0" top="0" right="0" bottom="0"/>
+
+ <!--- drop shadow can't be hittable so all other graphics go in this group -->
+ <s:Group left="0" right="0" top="0" bottom="0">
+
+ <!--- top group mask @private-->
+ <s:Group left="1" top="1" right="1" bottom="1" id="topGroupMask">
+ <!--- @private-->
+ <s:Rect id="topMaskRect" left="0" top="0" right="0" bottom="0">
+ <s:fill>
+ <s:SolidColor alpha="0"/>
+ </s:fill>
+ </s:Rect>
+ </s:Group>
+
+ <!--- bottom group mask @private-->
+ <s:Group left="1" top="1" right="1" bottom="1" id="bottomGroupMask"
+ includeIn="withControls">
+ <!--- @private-->
+ <s:Rect id="bottomMaskRect" left="0" top="0" right="0" bottom="0">
+ <s:fill>
+ <s:SolidColor alpha="0"/>
+ </s:fill>
+ </s:Rect>
+ </s:Group>
+
+ <!--- layer 1: border @private -->
+ <s:Rect id="border" left="0" right="0" top="0" bottom="0" radiusX="8">
+ <s:stroke>
+ <!--- Defines the TitleWindowSkin class's border stroke. The default value is 1. /////// HS ! ///////////-->
+ <s:SolidColorStroke id="borderStroke" weight="1" color="0xff0000"/>
+ </s:stroke>
+ </s:Rect>
+
+ <!-- layer 2: background fill -->
+ <!--- Defines the appearance of the TitleWindowSkin class's background. /////// HS ! /////////////////////-->
+ <s:Rect id="background" left="1" top="1" right="1" bottom="1" >
+ <s:fill>
+ <!--- Defines the TitleWindowSkin class's background fill. The default color is 0xFFFFFF. -->
+ <s:SolidColor id="backgroundFill" color="0x70a6d2" />
+ </s:fill>
+ </s:Rect>
+
+ <!-- layer 3: contents -->
+ <!--- Contains the vertical stack of title bar content and control bar. //////////////////////////-->
+ <s:Group left="1" right="1" top="1" bottom="1" id="contents" height="40">
+ <s:layout>
+ <s:VerticalLayout gap="0" horizontalAlign="justify" />
+ </s:layout>
+ <!--- @private -->
+ <s:Group id="topGroup" mask="{topGroupMask}">
+
+ <!--- layer 0: title bar fill @private /////////////////////////////////////////////////////-->
+ <s:Rect id="tbFill" left="0" right="0" top="0" bottom="1">
+ <s:fill>
+ <s:LinearGradient rotation="90">
+ <s:GradientEntry color="0x70a6d2"
+ /> <!--color.inactiveGroup="0xEAEAEA"-->
+ <s:GradientEntry color="0xdceefd"
+ /> <!--color.inactiveGroup="0xCECECE"-->
+ </s:LinearGradient>
+ </s:fill>
+ </s:Rect>
+
+ <!--- layer 1: title bar highlight @private ////////////////////////////////////////////////-->
+ <!--<s:Rect id="tbHilite" left="0" right="0" top="0" bottom="0">
+ <s:stroke>
+ <s:LinearGradientStroke rotation="90" weight="1">
+ <s:GradientEntry color="0x70a6d2" />
+ <s:GradientEntry color="0xFFFFFF" alpha="0.22"/>
+ </s:LinearGradientStroke>
+ </s:stroke>
+ <s:fill>
+ <s:LinearGradient rotation="90">
+ <s:GradientEntry color="0xa9d1f2" alpha="0.15" />
+ <s:GradientEntry color="0xa9d1f2" alpha="0.15" ratio="0.44"/>
+ <s:GradientEntry color="0xa9d1f2" alpha="0" ratio="0.4401"/>
+ </s:LinearGradient>
+ </s:fill>
+ </s:Rect>-->
+
+ <!--- layer 2: title bar divider @private ///////////////////////////////////////////////-->
+ <s:Rect id="tbDiv" left="0" right="0" height="1" bottom="0">
+ <s:fill>
+ <s:SolidColor color="0xffffff" alpha="0.75" />
+ </s:fill>
+ </s:Rect>
+
+ <!-- layer 3: text -->
+ <!--- @copy spark.components.Panel#titleDisplay ////////////////////////////////////////////-->
+ <s:Label id="titleDisplay" maxDisplayedLines="1"
+ left="9" right="36" top="1" bottom="0" minHeight="30"
+ verticalAlign="middle" fontWeight="bold" color="0x183d5b"/>
+
+ <!-- layer 4: moveArea -->
+ <!--- @copy spark.components.TitleWindow#moveArea -->
+ <s:Group id="moveArea" left="0" right="0" top="0" bottom="0" />
+
+ <!--- @copy spark.components.TitleWindow#closeButton -->
+ <s:Button id="closeButton" skinClass="spark.skins.spark.TitleWindowCloseButtonSkin"
+ width="15" height="15" right="7" top="7" />
+ </s:Group>
+
+ <!--
+ Note: setting the minimum size to 0 here so that changes to the host component's
+ size will not be thwarted by this skin part's minimum size. This is a compromise,
+ more about it here: http://bugs.adobe.com/jira/browse/SDK-21143
+ -->
+ <!--- @copy spark.components.SkinnableContainer#contentGroup -->
+ <s:Group id="contentGroup" width="100%" height="100%" minWidth="0" minHeight="0">
+ </s:Group>
+
+ <!--- @private ////////////////////////////////////////////////////////////////////////////-->
+ <s:Group id="bottomGroup" minWidth="0" minHeight="0"
+ includeIn="withControls">
+
+ <s:Group left="0" right="0" top="0" bottom="0" mask="{bottomGroupMask}">
+
+ <!-- layer 0: control bar divider line -->
+ <!--<s:Rect left="0" right="0" top="0" height="1" alpha="0.22">
+ <s:fill>
+ <s:SolidColor color="0xff0000" />
+ </s:fill>
+ </s:Rect>-->
+
+ <!-- layer 1: control bar highlight -->
+ <s:Rect left="0" right="0" top="1" bottom="0">
+ <s:stroke>
+ <s:LinearGradientStroke rotation="90" weight="1">
+ <s:GradientEntry color="0xFFFFFF" />
+ <s:GradientEntry color="0x70a6d2" />
+ </s:LinearGradientStroke>
+ </s:stroke>
+ </s:Rect>
+
+ <!-- layer 2: control bar fill -->
+ <s:Rect left="1" right="1" top="2" bottom="1">
+ <s:fill>
+ <s:LinearGradient rotation="90">
+ <s:GradientEntry color="0xdceefd"/> <!--0xEDEDED-->
+ <s:GradientEntry color="0x70a6d2"/>
+ </s:LinearGradient>
+ </s:fill>
+ </s:Rect>
+ </s:Group>
+
+ <!--- @copy spark.components.Panel#controlBarGroup -->
+ <s:Group id="controlBarGroup" left="0" right="0" top="1" bottom="1" minWidth="0" minHeight="0">
+ <s:layout>
+ <s:HorizontalLayout paddingLeft="10" paddingRight="10" paddingTop="7" paddingBottom="7" gap="10" />
+ </s:layout>
+ </s:Group>
+ </s:Group>
+ </s:Group>
+ </s:Group>
+</s:SparkSkin>
+
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/FlexPMD61.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/FlexPMD61.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/FlexPMD61.as
new file mode 100644
index 0000000..dc71301
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/FlexPMD61.as
@@ -0,0 +1,42 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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
+{
+ import flash.events.Event;
+
+ public class TestEvent extends Event
+ {
+ public function TestEvent(type:String, bubbles:Boolean=false, cancelable:Boolean=false, eventTime:Date=null) {
+ super(type, bubbles, cancelable);
+ _eventTime = eventTime;
+ }
+
+ override public function clone():Event {
+ return new TestEvent(type, bublles, cancelable, eventTime);
+ }
+
+ public function get eventTime() : Date {
+ return _eventTime;
+ }
+
+ private var _eventTime : Date;
+
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/FlexPMD62.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/FlexPMD62.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/FlexPMD62.as
new file mode 100644
index 0000000..939f879
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/FlexPMD62.as
@@ -0,0 +1,35 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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.test.testy.ui.components {
+
+ import flash.display.Sprite;
+
+ public class Link extends Sprite {
+
+ protected var _linkText:String = '';
+ protected var _style:String;
+
+ public function Link(text:String = '', style:String = null) {
+
+ _style = style;
+ _linkText = text;
+ }
+
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/FlexPMD88.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/FlexPMD88.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/FlexPMD88.as
new file mode 100644
index 0000000..81bdfdb
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/FlexPMD88.as
@@ -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
+{
+ import flashx.textLayout.elements.BreakElement;
+ import flashx.textLayout.elements.ParagraphElement;
+
+ public class BugDemo
+ {
+ public function BugDemo()
+ {
+ var paragraph : ParagraphElement = new ParagraphElement();
+ paragraph.addChild(new BreakElement());
+ var iii : int = 0; // NO PMD AlertShow
+ var iiii : int = 0; // NO PMD AlertShowRule
+ var iiiii : int = 0; // NO PMD com.adobe.ac.pmd.rules.maintanability.AlertShow
+ var iiiiii : int = 0; // NO PMD com.adobe.ac.pmd.rules.maintanability.AlertShowRule
+
+ for (var i:int = 0; i < 2; i++)
+ for (var j:int = 0; j < 2; j++)
+ blabla;
+ }
+
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/FlexPMD97.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/FlexPMD97.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/FlexPMD97.as
new file mode 100644
index 0000000..26b4769
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/FlexPMD97.as
@@ -0,0 +1,31 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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
+{
+ public class LogUtil
+ {
+ {
+ initLogging();
+ }
+
+ private static function initLogging():void
+ {
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/Nico.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/Nico.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/Nico.as
new file mode 100644
index 0000000..bc14610
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/Nico.as
@@ -0,0 +1,30 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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.search.api.domain {
+
+ import mx.collections.ArrayCollection;
+ import mx.messaging.channels.StreamingAMFChannel;
+
+ [Event(name="MoveToOffline", type="com.search.api.application.event.MoveOnlineReportToOfflineEvent")]
+ [ManagedEvents("MoveToOffline")]
+
+ public class Nico
+ {
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/Security.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/Security.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/Security.as
new file mode 100644
index 0000000..4435735
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/Security.as
@@ -0,0 +1,36 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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
+{
+ public class Security
+ {
+ public static function read() : void
+ {
+ Security.allowDomain("www.google.com");
+ Security.allowDomain("*");
+ Security.allowInsecureDomain("www.google.com");
+ Security.allowInsecureDomain("*");
+ Security.exactSettings = false;
+ LocalConnection.allowDomain("*");
+ LocalConnection.allowDomain("www.example.org");
+ LSO.getLocal(name, null, true);
+ LSO.getLocal(name, null, false);
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/cairngorm/BindableModelLocator.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/cairngorm/BindableModelLocator.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/cairngorm/BindableModelLocator.as
new file mode 100644
index 0000000..73bdc38
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/cairngorm/BindableModelLocator.as
@@ -0,0 +1,23 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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 {
+ [Bindable]
+ protected class BindableModelLocator implements GoodModelLocator {
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/cairngorm/FatController.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/cairngorm/FatController.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/cairngorm/FatController.as
new file mode 100644
index 0000000..b87780e
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/cairngorm/FatController.as
@@ -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.portal.Control
+{
+import com.portal.control.events.LoadUserProfileEvent;
+import com.portal.control.commands.LoadUserProfileCommand;
+ import com.adobe.cairngorm.control.FrontController;
+ import com.platform.control.commands.community.LoadFavoriteModulesCommand;
+ import com.platform.control.commands.contentbrowsing.LoadBrowsableKnowledgeCommand;
+ import com.platform.control.commands.contentbrowsing.UpdateBrowsableKnowledgeCommand;
+ import com.platform.control.commands.core.InitializeApplicationCommand;
+ import com.platform.control.commands.learnmanagement.LoadExerciseContentTreeCommand;
+ import com.platform.control.commands.learnmanagement.LoadTrainingCenterStatisticCommand;
+ import com.platform.control.commands.notifications.LoadNotificationsCommand;
+ import com.platform.control.commands.personalrecord.LoadPersonalRecordCommand;
+ import com.platform.control.commands.personalrecord.UpdatePersonalRecordCommand;
+ import com.platform.control.events.community.LoadFavoriteModulesEvent;
+ import com.platform.control.events.contentbrowsing.LoadBrowsableKnowledgeEvent;
+ import com.platform.control.events.contentbrowsing.UpdateBrowsableKnowledgeEvent;
+ import com.platform.control.events.core.InitializeApplicationEvent;
+ import com.platform.control.events.learnmanagement.LoadExerciseContentTreeEvent;
+ import com.platform.control.events.learnmanagement.LoadTrainingCenterStatisticEvent;
+ import com.platform.control.events.notificationbox.LoadNotificationsEvent;
+ import com.platform.control.events.personalrecord.LoadPersonalRecordEvent;
+ import com.platform.control.events.personalrecord.UpdatePersonalRecordEvent;
+ import com.portal.control.commands.AcceptFriendshipCommand;
+ import com.portal.control.commands.CancelFriendshipCommand;
+ import com.portal.control.commands.DismissNotificationCommand;
+ import com.portal.control.commands.LoadKnowledgeTreeCommand;
+ import com.portal.control.commands.LoadRecentActivitiesCommand;
+ import com.portal.control.commands.RejectFriendshipCommand;
+ import com.portal.control.commands.ReloadBuddiesCommand;
+ import com.portal.control.commands.SaveMyProfileCommand;
+ import com.portal.control.commands.SaveUserCommand;
+ import com.portal.control.commands.SearchUsersCommand;
+ import com.portal.control.commands.SendFeedbackCommand;
+ import com.portal.control.commands.SendLogoutCommand;
+ import com.portal.control.commands.ShowHelpCommand;
+ import com.portal.control.commands.StartFriendshipCommand;
+ import com.portal.control.commands.URLLoaderCommand;
+ import com.portal.control.commands.XMLParseCommand;
+ import com.portal.control.events.AcceptFriendshipEvent;
+ import com.portal.control.events.CancelFriendshipEvent;
+ import com.portal.control.events.DismissNotificationEvent;
+ import com.portal.control.events.LoadKnowledgeTreeEvent;
+ import com.portal.control.events.LoadRecentActivitiesEvent;
+ import com.portal.control.events.RejectFriendshipEvent;
+ import com.portal.control.events.ReloadBuddiesEvent;
+ import com.portal.control.events.SaveMyProfileEvent;
+ import com.portal.control.events.SaveUserEvent;
+ import com.portal.control.events.SearchUsersEvent;
+ import com.portal.control.events.SendFeedbackEvent;
+ import com.portal.control.events.SendLogoutEvent;
+ import com.portal.control.events.ShowHelpEvent;
+ import com.portal.control.events.StartFriendshipEvent;
+ import com.portal.control.events.URLLoaderEvent;
+ import com.portal.control.events.XMLParseEvent;
+ import com.ecs.control.events.LoadArticleEvent;
+ import com.ecs.control.commands.LoadArticleCommand;
+ import com.ecs.control.commands.LoadMagazineCommand;
+ import com.ecs.control.events.LoadMagazineEvent;
+ import mx.binding.utils.BindingUtils;
+
+ /**
+ * The main cairngorm controller. This defines the connections between the events and the commands
+ */
+ public class Controller extends FrontController
+ {
+ public function Controller()
+ {
+ BindingUtils.bindSetter(setContent, value, "content");
+ addCommand(
+ InitializeApplicationEvent.EVENT_TYPE,
+ InitializeApplicationCommand );
+ addCommand(
+ StartFriendshipEvent.EVENT_NAME,
+ StartFriendshipCommand );
+ addCommand(
+ LoadNotificationsEvent.EVENT_TYPE,
+ LoadNotificationsCommand );
+ addCommand(
+ DismissNotificationEvent.EVENT_NAME,
+ DismissNotificationCommand );
+ addCommand(
+ AcceptFriendshipEvent.EVENT_NAME,
+ AcceptFriendshipCommand );
+ addCommand(
+ CancelFriendshipEvent.EVENT_NAME,
+ CancelFriendshipCommand );
+ addCommand(
+ RejectFriendshipEvent.EVENT_NAME,
+ RejectFriendshipCommand );
+ addCommand(
+ SearchUsersEvent.EVENT_NAME,
+ SearchUsersCommand );
+// addCommand(
+// LoadBuddiesEvent.EVENT_TYPE,
+// LoadBuddiesCommand );
+ addCommand(
+ LoadKnowledgeTreeEvent.EVENT_NAME,
+ LoadKnowledgeTreeCommand );
+ addCommand(
+ LoadExerciseContentTreeEvent.EVENT_NAME,
+ LoadExerciseContentTreeCommand );
+ addCommand(
+ LoadBrowsableKnowledgeEvent.EVENT_NAME,
+ LoadBrowsableKnowledgeCommand );
+ addCommand(
+ UpdateBrowsableKnowledgeEvent.EVENT_NAME,
+ UpdateBrowsableKnowledgeCommand );
+ addCommand(
+ ShowHelpEvent.EVENT_NAME,
+ ShowHelpCommand );
+ addCommand(
+ URLLoaderEvent.EVENT_NAME,
+ URLLoaderCommand );
+ addCommand(
+ XMLParseEvent.EVENT_NAME,
+ XMLParseCommand );
+// addCommand(
+// LoadAmbitiousUsersEvent.EVENT_TYPE,
+// LoadAmbitiousUsersCommand );
+// addCommand(
+// LoadNewUsersEvent.EVENT_TYPE,
+// LoadNewUsersCommand );
+ addCommand(
+ LoadFavoriteModulesEvent.EVENT_TYPE,
+ LoadFavoriteModulesCommand );
+ addCommand(
+ SaveUserEvent.EVENT_NAME,
+ SaveUserCommand );
+ addCommand(
+ SendLogoutEvent.EVENT_NAME,
+ SendLogoutCommand );
+ addCommand(
+ SendFeedbackEvent.EVENT_NAME,
+ SendFeedbackCommand );
+ addCommand(
+ LoadPersonalRecordEvent.EVENT_TYPE,
+ LoadPersonalRecordCommand );
+ addCommand(
+ UpdatePersonalRecordEvent.EVENT_NAME,
+ UpdatePersonalRecordCommand );
+ addCommand(
+ SaveMyProfileEvent.EVENT_NAME,
+ SaveMyProfileCommand );
+ addCommand(
+ LoadUserProfileEvent.EVENT_NAME,
+ LoadUserProfileCommand );
+ addCommand(
+ ReloadBuddiesEvent.EVENT_NAME,
+ ReloadBuddiesCommand );
+ addCommand(
+ LoadRecentActivitiesEvent.EVENT_NAME,
+ LoadRecentActivitiesCommand );
+ addCommand(
+ LoadTrainingCenterStatisticEvent.EVENT_NAME,
+ LoadTrainingCenterStatisticCommand );
+ addCommand(
+ LoadMagazineEvent.EVENT_NAME,
+ LoadMagazineCommand );
+ addCommand(
+ LoadArticleEvent.EVENT_NAME,
+ LoadArticleCommand );
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/cairngorm/LightController.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/cairngorm/LightController.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/cairngorm/LightController.as
new file mode 100644
index 0000000..e5a5c24
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/cairngorm/LightController.as
@@ -0,0 +1,201 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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.portal.control
+{
+import com.portal.control.events.LoadUserProfileEvent;
+import com.portal.control.commands.LoadUserProfileCommand;
+ import com.adobe.cairngorm.control.FrontController;
+ import com.platform.control.commands.community.LoadFavoriteModulesCommand;
+ import com.platform.control.commands.contentbrowsing.LoadBrowsableKnowledgeCommand;
+ import com.platform.control.commands.contentbrowsing.UpdateBrowsableKnowledgeCommand;
+ import com.platform.control.commands.core.InitializeApplicationCommand;
+ import com.platform.control.commands.learnmanagement.LoadExerciseContentTreeCommand;
+ import com.platform.control.commands.learnmanagement.LoadTrainingCenterStatisticCommand;
+ import com.platform.control.commands.notifications.LoadNotificationsCommand;
+ import com.platform.control.commands.personalrecord.LoadPersonalRecordCommand;
+ import com.platform.control.commands.personalrecord.UpdatePersonalRecordCommand;
+ import com.platform.control.events.community.LoadFavoriteModulesEvent;
+ import com.platform.control.events.contentbrowsing.LoadBrowsableKnowledgeEvent;
+ import com.platform.control.events.contentbrowsing.UpdateBrowsableKnowledgeEvent;
+ import com.platform.control.events.core.InitializeApplicationEvent;
+ import com.platform.control.events.learnmanagement.LoadExerciseContentTreeEvent;
+ import com.platform.control.events.learnmanagement.LoadTrainingCenterStatisticEvent;
+ import com.platform.control.events.notificationbox.LoadNotificationsEvent;
+ import com.platform.control.events.personalrecord.LoadPersonalRecordEvent;
+ import com.platform.control.events.personalrecord.UpdatePersonalRecordEvent;
+ import com.portal.control.commands.AcceptFriendshipCommand;
+ import com.portal.control.commands.CancelFriendshipCommand;
+ import com.portal.control.commands.DismissNotificationCommand;
+ import com.portal.control.commands.LoadKnowledgeTreeCommand;
+ import com.portal.control.commands.LoadRecentActivitiesCommand;
+ import com.portal.control.commands.RejectFriendshipCommand;
+ import com.portal.control.commands.ReloadBuddiesCommand;
+ import com.portal.control.commands.SaveMyProfileCommand;
+ import com.portal.control.commands.SaveUserCommand;
+ import com.portal.control.commands.SearchUsersCommand;
+ import com.portal.control.commands.SendFeedbackCommand;
+ import com.portal.control.commands.SendLogoutCommand;
+ import com.portal.control.commands.ShowHelpCommand;
+ import com.portal.control.commands.StartFriendshipCommand;
+ import com.portal.control.commands.URLLoaderCommand;
+ import com.portal.control.commands.XMLParseCommand;
+ import com.portal.control.events.AcceptFriendshipEvent;
+ import com.portal.control.events.CancelFriendshipEvent;
+ import com.portal.control.events.DismissNotificationEvent;
+ import com.portal.control.events.LoadKnowledgeTreeEvent;
+ import com.portal.control.events.LoadRecentActivitiesEvent;
+ import com.portal.control.events.RejectFriendshipEvent;
+ import com.portal.control.events.ReloadBuddiesEvent;
+ import com.portal.control.events.SaveMyProfileEvent;
+ import com.portal.control.events.SaveUserEvent;
+ import com.portal.control.events.SearchUsersEvent;
+ import com.portal.control.events.SendFeedbackEvent;
+ import com.portal.control.events.SendLogoutEvent;
+ import com.portal.control.events.ShowHelpEvent;
+ import com.portal.control.events.StartFriendshipEvent;
+ import com.portal.control.events.URLLoaderEvent;
+ import com.portal.control.events.XMLParseEvent;
+ import com.ecs.control.events.LoadArticleEvent;
+ import com.ecs.control.commands.LoadArticleCommand;
+ import com.ecs.control.commands.LoadMagazineCommand;
+ import com.ecs.control.events.LoadMagazineEvent;
+
+ /**
+ * The main cairngorm controller. This defines the connections between the events and the commands
+ */
+ public class Controller extends FrontController
+ {
+ public function Controller()
+ {
+ addCommand(
+ InitializeApplicationEvent.EVENT_TYPE,
+ InitializeApplicationCommand );
+ addCommand(
+ StartFriendshipEvent.EVENT_NAME,
+ StartFriendshipCommand );
+ addCommand(
+ LoadNotificationsEvent.EVENT_TYPE,
+ LoadNotificationsCommand );
+ addCommand(
+ DismissNotificationEvent.EVENT_NAME,
+ DismissNotificationCommand );
+ addCommand(
+ AcceptFriendshipEvent.EVENT_NAME,
+ AcceptFriendshipCommand );
+ }
+
+ private function initCommand1() : void
+ {
+ addCommand(
+ CancelFriendshipEvent.EVENT_NAME,
+ CancelFriendshipCommand );
+ addCommand(
+ RejectFriendshipEvent.EVENT_NAME,
+ RejectFriendshipCommand );
+ addCommand(
+ SearchUsersEvent.EVENT_NAME,
+ SearchUsersCommand );
+// addCommand(
+// LoadBuddiesEvent.EVENT_TYPE,
+// LoadBuddiesCommand );
+ addCommand(
+ LoadKnowledgeTreeEvent.EVENT_NAME,
+ LoadKnowledgeTreeCommand );
+ }
+
+ private function initCommand1() : void
+ {
+ addCommand(
+ LoadExerciseContentTreeEvent.EVENT_NAME,
+ LoadExerciseContentTreeCommand );
+ addCommand(
+ LoadBrowsableKnowledgeEvent.EVENT_NAME,
+ LoadBrowsableKnowledgeCommand );
+ addCommand(
+ UpdateBrowsableKnowledgeEvent.EVENT_NAME,
+ UpdateBrowsableKnowledgeCommand );
+ addCommand(
+ ShowHelpEvent.EVENT_NAME,
+ ShowHelpCommand );
+ addCommand(
+ URLLoaderEvent.EVENT_NAME,
+ URLLoaderCommand );
+ }
+
+ protected function initCommand1() : void
+ {
+ addCommand(
+ XMLParseEvent.EVENT_NAME,
+ XMLParseCommand );
+// addCommand(
+// LoadAmbitiousUsersEvent.EVENT_TYPE,
+// LoadAmbitiousUsersCommand );
+// addCommand(
+// LoadNewUsersEvent.EVENT_TYPE,
+// LoadNewUsersCommand );
+ addCommand(
+ LoadFavoriteModulesEvent.EVENT_TYPE,
+ LoadFavoriteModulesCommand );
+ addCommand(
+ SaveUserEvent.EVENT_NAME,
+ SaveUserCommand );
+ }
+
+ private function initCommand1() : void
+ {
+ addCommand(
+ SendLogoutEvent.EVENT_NAME,
+ SendLogoutCommand );
+ addCommand(
+ SendFeedbackEvent.EVENT_NAME,
+ SendFeedbackCommand );
+ addCommand(
+ LoadPersonalRecordEvent.EVENT_TYPE,
+ LoadPersonalRecordCommand );
+ addCommand(
+ UpdatePersonalRecordEvent.EVENT_NAME,
+ UpdatePersonalRecordCommand );
+ addCommand(
+ SaveMyProfileEvent.EVENT_NAME,
+ SaveMyProfileCommand );
+ }
+
+ private function initCommand1() : void
+ {
+ addCommand(
+ LoadUserProfileEvent.EVENT_NAME,
+ LoadUserProfileCommand );
+ addCommand(
+ ReloadBuddiesEvent.EVENT_NAME,
+ ReloadBuddiesCommand );
+ addCommand(
+ LoadRecentActivitiesEvent.EVENT_NAME,
+ LoadRecentActivitiesCommand );
+ addCommand(
+ LoadTrainingCenterStatisticEvent.EVENT_NAME,
+ LoadTrainingCenterStatisticCommand );
+ addCommand(
+ LoadMagazineEvent.EVENT_NAME,
+ LoadMagazineCommand );
+ addCommand(
+ LoadArticleEvent.EVENT_NAME,
+ LoadArticleCommand );
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/cairngorm/NonBindableModelLocator.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/cairngorm/NonBindableModelLocator.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/cairngorm/NonBindableModelLocator.as
new file mode 100644
index 0000000..fc058d2
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/cairngorm/NonBindableModelLocator.as
@@ -0,0 +1,54 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package com.adobe.ac.sample.model
+{
+ import com.adobe.ac.sample.view.common.model.UsersManagementPresentationModel;
+ import com.adobe.cairngorm.model.IModelLocator;
+
+ private class ModelLocator implements IModelLocator
+ {
+ private static var _instance : ModelLocator;
+ protected var myProtected : int;
+ [Bindable]
+ public var usersManager : UsersManagementPresentationModel;
+
+ public function ModelLocator( enforcer : SingletonEnforcer )
+ {
+ usersManager = new UsersManagementPresentationModel();
+ }
+
+ public static function get instance() : ModelLocator
+ {
+ if ( _instance == null )
+ {
+ foo();
+ _instance = new ModelLocator( new SingletonEnforcer() );
+ }
+ return _instance;
+ }
+
+ [Bindable]
+ public function get height() : int
+ {
+ return 0;
+ }
+ }
+}
+
+class SingletonEnforcer{}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/cairngorm/events/CorrectConstantEvent.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/cairngorm/events/CorrectConstantEvent.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/cairngorm/events/CorrectConstantEvent.as
new file mode 100644
index 0000000..fa933b5
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/cairngorm/events/CorrectConstantEvent.as
@@ -0,0 +1,45 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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 cairngorm.events
+{
+ import com.adobe.cairngorm.enterprise.control.event.CairngormEnterpriseEvent;
+ import com.adobe.cairngorm.enterprise.model.IModel;
+
+ import flash.events.Event;
+
+ public class CorrectConstantEvent extends CairngormEnterpriseEvent
+ {
+ public static const EVENT_NAME : String = "functionalArea.eventName";
+
+ public function CorrectConstantEvent( model : IModel )
+ {
+ super( EVENT_NAME, model );
+ usedEmptyMethod();
+ }
+
+ public override function clone() : Event
+ {
+ return new CorrectConstantEvent( model );
+ }
+
+ private function usedEmptyMethod() : void
+ {
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/cairngorm/events/CorrectConstructorEvent.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/cairngorm/events/CorrectConstructorEvent.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/cairngorm/events/CorrectConstructorEvent.as
new file mode 100644
index 0000000..debc558
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/cairngorm/events/CorrectConstructorEvent.as
@@ -0,0 +1,38 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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 cairngorm.events
+{
+ import com.adobe.cairngorm.enterprise.control.event.CairngormEnterpriseEvent;
+ import com.adobe.cairngorm.enterprise.model.IModel;
+
+ import flash.events.Event;
+
+ public class CorrectConstructorEvent extends CairngormEvent
+ {
+ public function CorrectConstructorEvent( model : IModel )
+ {
+ super( "functionalArea.eventName", model );
+ }
+
+ public override function clone() : Event
+ {
+ return new EventNameEvent( model );
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/cairngorm/events/UncorrectConstantEvent.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/cairngorm/events/UncorrectConstantEvent.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/cairngorm/events/UncorrectConstantEvent.as
new file mode 100644
index 0000000..12edc78
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/cairngorm/events/UncorrectConstantEvent.as
@@ -0,0 +1,40 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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 cairngorm.events
+{
+ import com.adobe.cairngorm.enterprise.control.event.CairngormEnterpriseEvent;
+ import com.adobe.cairngorm.enterprise.model.IModel;
+
+ import flash.events.Event;
+
+ public class UncorrectConstantEvent extends CairngormEnterpriseEvent
+ {
+ public static const EVENT_NAME : String = "eventName";
+
+ public function UncorrectConstantEvent( model : IModel )
+ {
+ super( EVENT_NAME, model );
+ }
+
+ public override function clone() : Event
+ {
+ return new UncorrectConstantEvent( model );
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/cairngorm/events/UncorrectConstructorEvent.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/cairngorm/events/UncorrectConstructorEvent.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/cairngorm/events/UncorrectConstructorEvent.as
new file mode 100644
index 0000000..2aae3ef
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/cairngorm/events/UncorrectConstructorEvent.as
@@ -0,0 +1,38 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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 cairngorm.events
+{
+ import com.adobe.cairngorm.enterprise.control.event.CairngormEnterpriseEvent;
+ import com.adobe.cairngorm.enterprise.model.IModel;
+
+ import flash.events.Event;
+
+ public class UncorrectConstructorEvent extends CairngormEvent
+ {
+ public function UncorrectConstructorEvent( model : IModel )
+ {
+ super( "eventName", model );
+ }
+
+ public override function clone() : Event
+ {
+ return new UncorrectConstructorEvent( model );
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/AbstractRowData.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/AbstractRowData.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/AbstractRowData.as
new file mode 100644
index 0000000..82bbc9d
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/AbstractRowData.as
@@ -0,0 +1,118 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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 flexunit.flexui.data
+{
+ import flexunit.flexui.controls.FlexUnitLabels;
+
+ import mx.formatters.NumberFormatter;
+
+ /**
+ * Abstract class representing a row in the test cases tree.
+ * A row can be either a test class (node) or a test case (leaf)
+ */
+ final public class AbstractRowData
+ {
+ public var label : String;
+ public var qualifiedClassName : String;
+ public var testSuccessful : Boolean;
+ public var testIsFailure : Boolean;
+
+ /**
+ * @return the class name from the qualified class name
+ */
+ public function get className() : String
+ {
+ if ( qualifiedClassName )
+ {
+ var splitIndex : int = qualifiedClassName.lastIndexOf( "::" );
+
+ if ( splitIndex >= 0 )
+ {
+ if ( true )
+ {
+ return qualifiedClassName.substring( splitIndex + 2 );
+ }
+ }
+ }
+
+ return qualifiedClassName;
+ }
+
+ /**
+ * Abstract method. Defined in TestCaseRowData and in TestClassRowData
+ *
+ * @return the count of assertions which have been made either in average if
+ * the current row is a test class or in total if the current row is a test case
+ */
+ public function get assertionsMade() : Number
+ {
+ throw new Error( "TestSummaryRowData::assertionsMade is an abstract method" );
+ }
+
+ public function get failIcon() : Class
+ {
+ throw new Error( "TestSummaryRowData::failIcon is an abstract method" );
+ }
+
+ public function get passIcon() : Class
+ {
+ throw new Error( "TestSummaryRowData::passIcon is an abstract method" );
+ }
+
+ /**
+ * Abstract method which allows the legend to be correctly formatted.
+ *
+ * @return true for the TestClassRowData and false for the TestCaseRowData
+ */
+ public function get isAverage() : Boolean
+ {
+ throw new Error( "TestSummaryRowData::isAverage is an abstract method" );
+ }
+
+ public function get formattedAssertionsMade() : String
+ {
+ var formatter : NumberFormatter = new NumberFormatter();
+
+ formatter.precision = 2;
+ formatter.rounding = "nearest";
+
+ return formatter.format( assertionsMade );
+ }
+
+ /**
+ * @return the correcly formatted (no typos) legend for the number of assertions
+ * made.
+ *
+ * Can return :
+ * - 0 assertions have been made in average
+ * - 0 assertions have been made in total
+ * - 1 assertion has been made in average
+ * - 1 assertion has been made in total
+ * - 2 assertions have been made in average
+ * - 2 assertions have been made in total
+ */
+ public function get assertionsMadeLegend() : String
+ {
+ return FlexUnitLabels.formatAssertions(
+ formattedAssertionsMade,
+ assertionsMade,
+ isAverage );
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/foo.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/foo.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/foo.as
new file mode 100644
index 0000000..01cc773
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/foo.as
@@ -0,0 +1,22 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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 {
+ public class foo {
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/ArrayVO.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/ArrayVO.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/ArrayVO.as
new file mode 100644
index 0000000..8259e96
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/ArrayVO.as
@@ -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 model.vo {
+ [Bindable]
+ public class ArrayVO {
+ public var items:Array;
+ /** Menu items of the menu */
+ [ArrayElementType("model.vo.MenuItemVO")]
+ public var variable : Array;
+ [ArrayElementType("model.vo.MenuItemVO")]
+ public const constant : Array = [];
+ public static const staticConstant : String = "";
+ public var first : String = "";
+ public var first : String = "";
+ public var first : String = "";
+ public var first : String = "";
+ public var first : String = "";
+ public var first : String = "";
+ public var first : String = "";
+ public var first : String = "";
+ public var first : String = "";
+ public var first : String = "";
+ public var first : String = "";
+ public var first : String = "";
+ public var first : String = "";
+ public var first : String = "";
+ public var first : String = "";
+ public var first : String = "";
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/BigImporterModel.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/BigImporterModel.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/BigImporterModel.as
new file mode 100644
index 0000000..f75f5bd
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/BigImporterModel.as
@@ -0,0 +1,78 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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
+{
+ import com.adobe.ac.lala;
+ import com.adobe.ac.ncss.lala;
+ import mx.controls.ComboBox;
+ import com.foo.frontendview.vo.PersonVO;
+ import lala;
+
+ import lala;
+
+ import lala;
+ import lala;
+ import lala;
+ import lala;
+ import lala;
+
+ import lala;
+
+ import lala;
+ import lala;
+ import lala;
+ import lala;
+
+ public class BigModel
+ {
+ public function BigModel()
+ {
+ dispatchEvent( new Event( "pointlessEvent" ) );
+ return;
+ }
+
+ public function foo( param1 : Number, param2 : Number, param3 : Number, param4 : Number, param5 : DataGridColumn ) : void
+ {
+ var iParam1 : int = param1;
+ }
+
+ public function updateIteration(iteration:IterationVO) : void
+ {
+ iteration.cascadeDatesChanges();
+ try {
+ AnthologyModel.getInstance().projectModel.iterationDataModel.commit();
+ }
+ catch(error:Error) {
+ trace("Error while persisting the edited iteration to the database");
+ trace(error.message);
+ }
+ }
+
+ public function createTestsForStory( story:StoryVO, responder:IResponder ):void
+ {
+ for each ( var test:CustomerTestVO in story.customerTests ) {
+ createTest( test );
+ }
+ var token:AsyncToken = dataService.commit();
+ if ( responder && token ) {
+ token.addResponder( responder );
+ }
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/BigModel.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/BigModel.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/BigModel.as
new file mode 100644
index 0000000..7f40222
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/BigModel.as
@@ -0,0 +1,90 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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
+{
+ import mx.controls.Alert;
+
+ public class BigModel
+ {
+ public var field : Number;
+ public var field : Number;
+ public var field : Number;
+ protected var field : Number;
+ private var field : Number;
+ private var field : Number;
+
+ public function BigModel()
+ {
+ return;
+ var iLala : lala;
+ }
+
+ public function foo() : void
+ {
+ }
+
+ public function foo() : void
+ {
+ }
+
+ public function foo() : void
+ {
+ }
+
+ public function foo() : void
+ {
+ }
+
+ public function foo() : void
+ {
+ }
+
+ public function foo() : void
+ {
+ }
+
+ public function foo() : void
+ {
+ }
+
+ public function foo() : void
+ {foo1();
+ }
+
+ private function foo1() : void
+ {
+ }
+
+ private function foo2() : void
+ {
+ }
+
+ private function foo3() : void
+ {
+ }
+
+ private function foo4() : void
+ {
+ }
+
+ private function foo5() : void
+ {
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/ConfigProxy.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/ConfigProxy.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/ConfigProxy.as
new file mode 100644
index 0000000..fa46745
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/ConfigProxy.as
@@ -0,0 +1,50 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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.model
+{
+ import com.model.VO.ConfigVO;
+
+ import de.polygonal.ds.HashMap;
+
+ public class ConfigProxy extends MS2Proxy
+ {
+ public static const NAME:String = "configProxy";
+ private static var configs:HashMap = new HashMap(MS2Proxy.HASHMAP_INITAL_SIZE);
+
+ public function ConfigProxy(bar:Object=null)
+ {
+ super(ConfigProxy.NAME, bar);
+ }
+
+ public static function populateStub():void {
+ Alert.show( "error" );
+ ConfigProxy.insertConfig(new ConfigVO(118218, order, 9000001, "fr", "default.css", "", 9000001));
+ }
+
+ internal static function insertConfig(configVO:ConfigVO):void {
+ try
+ {
+ ConfigProxy.configs.remove(Number(configVO.idUser));
+ }
+ catch( e : Exception )
+ {
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/LongSwitch.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/LongSwitch.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/LongSwitch.as
new file mode 100644
index 0000000..59ba709
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/LongSwitch.as
@@ -0,0 +1,132 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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
+{
+ public class BigModel
+ {
+ public function BigModel()
+ {
+ }
+
+ public function foo() : void
+ {
+ switch(event.type){
+ case GoogleSearchPanel.LAUNCH_GOOGLE_WEB_SEARCH:
+ googleResquest.url = "";
+ toto();
+ break;
+ case GoogleSearchPanel.LAUNCH_GOOGLE_IMAGE_SEARCH:
+ googleResquest.url = "";
+ vfdvfdvfd;
+ vfdvdfvgfnbrn;
+ break;
+ case GoogleSearchPanel.LAUNCH_GOOGLE_NEWS_SEARCH:
+ googleResquest.url = "";
+ switch (e.oldState) {
+ case STATE_COMPARE_VIEW :
+ createPlaceHolders();
+ createPlaceHolderLabels();
+ break;
+ case STATE_COMPARE_VIEW :
+ if (productsInCompare.length < 3) {
+ drawPlaceHolder(PLACEHOLDER_COORDS[2] as Point);
+ lastPlaceholderLabel = createPlaceHolderLabel(PLACEHOLDER_COORDS[2] as Point);
+ }
+ showCompareButton();
+ break;
+ }
+ break;
+ }
+ testCase.setTestResult( this );
+
+ var protectedTestCase : Protectable = Protectable( new ProtectedStartTestCase( testCase ) );
+
+ var startOK : Boolean = doProtected( testCase, protectedTestCase );
+
+ if ( startOK )
+ {
+ doContinue( testCase );
+ }
+ else
+ {
+ endTest( testCase );
+ }
+ var startOK : Boolean = doProtected( testCase, protectedTestCase );
+
+ if ( startOK )
+ {
+ doContinue( testCase );
+ }
+ else
+ {
+ endTest( testCase );
+ }
+ switch(event.type){
+ case GoogleSearchPanel.LAUNCH_GOOGLE_WEB_SEARCH:
+ googleResquest.url = "";
+ break;
+ case GoogleSearchPanel.LAUNCH_GOOGLE_IMAGE_SEARCH:
+ googleResquest.url = "";
+ break;
+ case GoogleSearchPanel.LAUNCH_GOOGLE_IMAGE_SEARCH2:
+ googleResquest.url = "";
+ break;
+ default:
+ }
+ }
+
+ public function fooBar() : void
+ {
+ try
+ {
+ var illl : int = 0;
+ do
+ {
+ illl++;
+ ;
+ }while(illl<10)
+ }
+ catch( e : Error )
+ {
+ {
+ Message.show("");
+ }
+ }
+ finally
+ {
+ trace("");
+ }
+
+ do
+ {
+ } while( i < 5 );
+
+ switch(event.type){
+ case GoogleSearchPanel.LAUNCH_GOOGLE_WEB_SEARCH:
+ googleResquest.url = "";
+ case GoogleSearchPanel.LAUNCH_GOOGLE_IMAGE_SEARCH:
+ case GoogleSearchPanel.LAUNCH_GOOGLE_IMAGE_SEARCH2:
+ googleResquest.url = "";
+ break;
+ default:
+ return;
+ }
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/MyCairngormCommand.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/MyCairngormCommand.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/MyCairngormCommand.as
new file mode 100644
index 0000000..e6a8735
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/MyCairngormCommand.as
@@ -0,0 +1,30 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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
+{
+ public class MyCairngormCommand implements ICommand
+ {
+ public function execute( event : CairngormEvent ) : void
+ {
+ var delegate : MyDelegate = new MyDelegate();
+
+ delegate.doSomething();
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/NestedSwitch.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/NestedSwitch.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/NestedSwitch.as
new file mode 100644
index 0000000..08b3d09
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/NestedSwitch.as
@@ -0,0 +1,59 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package view {
+
+ public class NestedPanel extends UIComponent
+ {
+ protected function currentStateChangeHandler(e:StateChangeEvent):void {
+ switch (e.newState) {
+ case STATE_PRODUCTS_IN_COMPARE :
+ hideCloseButton();
+ height = 230;
+ borderBreakPointX = BORDER_BREAK_POINT.x;
+ borderBreakPointY = BORDER_BREAK_POINT.y;
+ drawCompareBackground();
+ switch (e.oldState) {
+ case "" :
+ createPlaceHolders();
+ createPlaceHolderLabels();
+ break;
+ case STATE_COMPARE_VIEW :
+ if (productsInCompare.length < 3) {
+ drawPlaceHolder(PLACEHOLDER_COORDS[2] as Point);
+ lastPlaceholderLabel = createPlaceHolderLabel(PLACEHOLDER_COORDS[2] as Point);
+ }
+ showCompareButton();
+ break;
+ }
+ break;
+ case STATE_COMPARE_VIEW :
+ if (productsInCompare.length < 3)
+ removeChild(lastPlaceholderLabel);
+ hideCompareButton();
+ showCloseButton();
+ createCompareInfoView();
+ break;
+ default :
+ height = 40;
+ drawDefaultBackground();
+ break;
+ }
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/SearchBarEvent.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/SearchBarEvent.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/SearchBarEvent.as
new file mode 100644
index 0000000..2bb4a64
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/SearchBarEvent.as
@@ -0,0 +1,34 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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 flexunit.flexui.controls.left.events
+{
+ import flash.events.Event;
+
+ public class SearchBarEvent extends Event
+ {
+ public static const FILTER_CHANGED_EVENT : String = "filterChanged";
+ public static const FILTER_TEXT_CHANGED_EVENT : String = "filterTextChanged";
+ public static const FILTER_RESULT_CHANGED_EVENT : String = "filterResultChanged";
+ public static const FILTER_ASSERTION_CHANGED_EVENT : String = "filterAssertionChanged";
+
+ public function SearchBarEvent( type : String ) {
+ super( type );
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/VoidConstructor.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/VoidConstructor.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/VoidConstructor.as
new file mode 100644
index 0000000..8420933
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/VoidConstructor.as
@@ -0,0 +1,37 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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
+{
+ public class VoidConstructor
+ {
+ public var iNumber : Number;
+
+ public function VoidConstructor() : void
+ {
+ return;
+ var iNumber : lala;
+ }
+
+ public function foo() : void
+ {
+ throw new Error( "" );
+ return null;
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/event/DynamicCustomEvent.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/event/DynamicCustomEvent.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/event/DynamicCustomEvent.as
new file mode 100644
index 0000000..036a046
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/com/adobe/ac/ncss/event/DynamicCustomEvent.as
@@ -0,0 +1,35 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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
+{
+ dynamic public class FirstCustomEvent extends Event
+ {
+ public var lala : String;
+
+ public function FirstCustomEvent()
+ {
+
+ }
+
+ public override function clone() : Event
+ {
+ return new FirstCustomEvent();
+ }
+ }
+}
\ No newline at end of file
[20/24] git commit: [flex-utilities]
[refs/heads/feature/pmd-5.2-language-module] - Initial commit of the PMD
language module for Apache Flex
Posted by cd...@apache.org.
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/test/resources/examples/Enum.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/parser/parser-impl/src/test/resources/examples/Enum.as b/FlexPMD/language-module/parser/parser-impl/src/test/resources/examples/Enum.as
new file mode 100644
index 0000000..358e103
--- /dev/null
+++ b/FlexPMD/language-module/parser/parser-impl/src/test/resources/examples/Enum.as
@@ -0,0 +1,84 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package org.granite.util
+{
+ import flash.utils.IDataInput;
+ import flash.utils.IDataOutput;
+ import flash.utils.IExternalizable;
+ import flash.utils.getQualifiedClassName;
+
+ public class Enum implements IExternalizable
+ {
+ private var _name:String;
+
+ public function Enum(name:String, restrictor:Restrictor) {
+ _name = (restrictor is Restrictor ? name : constantOf(name).name);
+ }
+
+ public function get name():String {
+ return _name;
+ }
+
+ protected function getConstants():Array {
+ throw new Error("Should be overriden");
+ }
+
+ protected function constantOf(name:String):Enum {
+ for each (var o:* in getConstants()) {
+ var enum:Enum = Enum(o);
+ if (enum.name == name)
+ return enum;
+ }
+ throw new ArgumentError("Invalid " + getQualifiedClassName(this) + " value: " + name);
+ }
+
+ public function readExternal(input:IDataInput):void {
+ _name = constantOf(input.readObject() as String).name;
+ }
+
+ public function writeExternal(output:IDataOutput):void {
+ output.writeObject(_name);
+ }
+
+ public static function normalize(enum:Enum):Enum {
+ return (enum == null ? null : enum.constantOf(enum.name));
+ }
+
+ public static function readEnum(input:IDataInput):Enum {
+ return normalize(input.readObject() as Enum);
+ }
+
+ public function toString():String {
+ return name;
+ }
+
+ public function equals(other:Enum):Boolean {
+ return other === this || (
+ other != null &&
+ getQualifiedClassName(this) == getQualifiedClassName(other) &&
+ other.name == this.name
+ );
+ }
+
+ protected static function get _():Restrictor { // NO PMD ProtectedStaticMethod
+ return new Restrictor();
+ }
+ }
+}
+class Restrictor {}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/test/resources/examples/FisheyeBase.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/parser/parser-impl/src/test/resources/examples/FisheyeBase.as b/FlexPMD/language-module/parser/parser-impl/src/test/resources/examples/FisheyeBase.as
new file mode 100644
index 0000000..fe2147a
--- /dev/null
+++ b/FlexPMD/language-module/parser/parser-impl/src/test/resources/examples/FisheyeBase.as
@@ -0,0 +1,564 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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 qs.controls.fisheyeClasses
+{
+ import flash.display.DisplayObject;
+ import flash.display.Sprite;
+ import flash.events.Event;
+ import flash.events.MouseEvent;
+ import mx.core.ClassFactory;
+ import mx.core.IDataRenderer;
+ import mx.core.IFactory;
+ import mx.core.UIComponent;
+ import qs.controls.CachedLabel;
+ import qs.controls.LayoutAnimator;
+
+ /** the horizontal alignment. */
+ [Style( name="horizontalAlign", type="String", enumeration="left,center,right,justified", inherit="no" )]
+ /** the vertical alignment */
+ [Style( name="verticalAlign", type="String", enumeration="top,center,bottom,justified", inherit="no" )]
+ /** the amount of space, in pixels, between invidual items */
+ [Style( name="defaultSpacing", type="Number", inherit="no" )]
+ /** the amount of space, in pixels, between invidual items when hilighted*/
+ [Style( name="hilightSpacing", type="Number", inherit="no" )]
+ /** the property on the item renderer to assign to when the renderer' state changes */
+ [Style( name="stateProperty", type="String", inherit="no" )]
+ /** the value to assign to 'stateProperty' on the renderer when the item is hilighted */
+ [Style( name="rolloverValue", type="String", inherit="no" )]
+ /** the value to assign to 'stateProperty' on the renderer when the item is selected */
+ [Style( name="selectedValue", type="String", inherit="no" )]
+ /** the value to assign to 'stateProperty' on the renderer when some other item is selected */
+ [Style( name="unselectedValue", type="String", inherit="no" )]
+ /** the value to assign to 'stateProperty' on the renderer when the item is in its default state */
+ [Style( name="defaultValue", type="String", inherit="no" )]
+ /** the scale factor assigned to renderers when no item is hilighted or selected */
+ [Style( name="defaultScale", type="Number", inherit="no" )]
+ /** the minimum scale factor assigned to renderers on screen. The actual scale factor assigned to
+ * an item will range between minScale and hilightMaxScale based on its distance from the hilighted or selected item */
+ [Style( name="hilightMinScale", type="Number", inherit="no" )]
+ /** the maximum scale factor assigned to renderers on screen. The actual scale factor assigned to
+ * an item will range between minScale and hilightMaxScale based on its distance from the hilighted or selected item */
+ [Style( name="hilightMaxScale", type="Number", inherit="no" )]
+ /** how quickly or slowly items scale down from the hilightMaxScale value to minScale value. A value of 1 will scale linearly down from the hilighted item out to the item at scaleRadius.
+ * A value higher than wone will descend slowly from the hilight, then drop off quicker at the edge. A value lower than one will drop off quickly from the hilight Should be greater than 0*/
+ [Style( name="hilightScaleSlope", type="Number", inherit="no" )]
+ /** The radius, in items, around the hilighted item that are affected by the hilight. A value of 1 means only the hilighted item will scale. A value of three means the hilighted item plus the two items
+ * to either side will scale up. How much each item scales is affected by the scaleSlope style.*/
+ [Style( name="hilightScaleRadius", type="Number", inherit="no" )]
+ /** how quickly items animate to their target location when the layout of the renderers change. A value of 1 will
+ * snap instantly to the new value, while a value of 0 will never change */
+ [Style( name="animationSpeed", type="Number", inherit="no" )]
+ [Event( name="change", type="flash.events.Event" )]
+ [Event( name="loaded", type="flash.events.Event" )]
+ [DefaultProperty( "dataProvider" )]
+ public class FisheyeBase extends UIComponent
+ {
+ public static const LOADED : String = "loaded";
+
+ /** the data items driving the component
+ */
+ private var _items : Array = [];
+
+ /** when a new dataprovider is assigned, we keep it in reserve until we have a chance
+ * to generate new renderers for it. This is the temporary holding pen for those new items
+ */
+ private var _pendingItems : Array;
+
+ protected var itemsChanged : Boolean = false;
+
+ /** true if the renderers need to be regenerated */
+ protected var renderersDirty : Boolean = true;
+
+ /** the renderers representing the data items, one for each item */
+ protected var renderers : Array = [];
+
+ /** the currently hilighted item
+ */
+ protected var hilightedItemIndex : Number = NaN;
+
+ /** the currently selected item
+ */
+ protected var selectedItemIndex : Number = NaN;
+
+ /** @private */
+ private var _selectionEnabled : Boolean = true;
+
+ /** the factory that generates item renderers
+ */
+ private var _itemRendererFactory : IFactory;
+
+ /**
+ * the object that manages animating the children layout
+ */
+ protected var animator : LayoutAnimator;
+
+ /** Constructor */
+ public function FisheyeBase()
+ {
+ super();
+ _itemRendererFactory = new ClassFactory( CachedLabel );
+ addEventListener( MouseEvent.MOUSE_MOVE, updateHilight );
+ addEventListener( MouseEvent.ROLL_OUT, removeHilight );
+ addEventListener( MouseEvent.MOUSE_DOWN, updateSelection );
+ var maskShape : Sprite = new Sprite();
+ addChild( maskShape );
+ mask = maskShape;
+ maskShape.graphics.beginFill( 0 );
+ maskShape.graphics.drawRect( 0, 0, 10, 10 );
+ maskShape.graphics.endFill();
+ animator = new LayoutAnimator();
+ animator.layoutFunction = generateLayout;
+ }
+
+ //-----------------------------------------------------------------
+ /** the data source
+ */
+ public function set dataProvider( value : Array ) : void
+ {
+ _pendingItems = value;
+ renderersDirty = true;
+ itemsChanged = true;
+ invalidateProperties();
+ dispatchEvent( new Event( LOADED ) );
+ }
+
+ public function get dataProvider() : Array
+ {
+ return _items;
+ }
+
+ //-----------------------------------------------------------------
+ public function set selectionEnabled( value : Boolean ) : void
+ {
+ if ( _selectionEnabled == value )
+ return;
+ _selectionEnabled = value;
+ selectedIndex = selectedIndex;
+ }
+
+ public function get selectionEnabled() : Boolean
+ {
+ return _selectionEnabled;
+ }
+
+ [Bindable( "change" )]
+ public function get selectedItem() : Object
+ {
+ return ( isNaN( selectedItemIndex ) ? null : _items[ selectedItemIndex ] );
+ }
+
+ public function set selectedItem( value : Object ) : void
+ {
+ var newIndex : Number;
+
+ for ( var i : int = 0; i < _items.length; i++ )
+ {
+ if ( value == _items[ i ] )
+ {
+ newIndex = i;
+ break;
+ }
+ }
+ selectedIndex = newIndex;
+ }
+
+ [Bindable( "change" )]
+ public function get selectedIndex() : int
+ {
+ return ( isNaN( selectedItemIndex ) ? -1 : selectedItemIndex );
+ }
+
+ public function set selectedIndex( value : int ) : void
+ {
+ var v : Number = ( value < 0 || value >= _items.length ) ? NaN : value;
+
+ if ( v != selectedItemIndex )
+ {
+ selectedItemIndex = v;
+ updateState();
+ animator.invalidateLayout();
+ dispatchEvent( new Event( LOADED ) );
+ }
+ }
+
+ //-----------------------------------------------------------------
+ /* These private get properties are wrappers around styles that return defaults if unset.
+ * It saves me from having to write a CSS selector, which
+ * I really should do at some point */
+ protected function get defaultSpacingWithDefault() : Number
+ {
+ var result : Number = getStyle( "defaultSpacing" );
+
+ if ( isNaN( result ) )
+ result = 0;
+ return result;
+ }
+
+ protected function get maxScaleWithDefault() : Number
+ {
+ var result : Number = getStyle( "hilightMaxScale" );
+
+ if ( isNaN( result ) )
+ result = 1;
+ return result;
+ }
+
+ //-----------------------------------------------------------------
+ /**
+ * by making the itemRenderer be of type IFactory,
+ * developers can define it inline using the <Component> tag
+ */
+ public function get itemRenderer() : IFactory
+ {
+ return _itemRendererFactory;
+ }
+
+ public function set itemRenderer( value : IFactory ) : void
+ {
+ _itemRendererFactory = value;
+ renderersDirty = true;
+ invalidateProperties();
+ }
+
+ //-----------------------------------------------------------------
+ override protected function commitProperties() : void
+ {
+ // its now safe to switch over new dataProviders.
+ if ( _pendingItems != null )
+ {
+ _items = _pendingItems;
+ _pendingItems = null;
+ }
+ itemsChanged = false;
+
+ if ( renderersDirty )
+ {
+ // something has forced us to reallocate our renderers. start by throwing out the old ones.
+ renderersDirty = false;
+ var mask : DisplayObject = mask;
+
+ for ( var i : int = numChildren - 1; i >= 0; i-- )
+ removeChildAt( i );
+ addChild( mask );
+ renderers = [];
+
+ // allocate new renderers, assign the data.
+ for ( i = 0; i < _items.length; i++ )
+ {
+ var renderer : UIComponent = _itemRendererFactory.newInstance();
+ IDataRenderer( renderer ).data = _items[ i ];
+ renderers[ i ] = renderer;
+ addChild( renderer );
+ }
+ animator.items = renderers;
+ }
+ invalidateSize();
+ }
+
+ private function removeHilight( e : MouseEvent ) : void
+ {
+ // called on rollout. Clear out any hilight, and reset our layout.
+ hilightedItemIndex = NaN;
+ updateState();
+ animator.invalidateLayout();
+ }
+
+ /** finds the item that would be closest to the x/y position if it were hilighted
+ */
+ protected function findItemForPosition( xPos : Number, yPos : Number ) : Number
+ {
+ return NaN;
+ }
+
+ /** called on mouse click to set or clear the selection */
+ protected function updateSelection( e : MouseEvent ) : void
+ {
+ if ( _selectionEnabled == false )
+ return;
+ var newSelection : Number = findItemForPosition( this.mouseX, this.mouseY );
+
+ if ( selectedItemIndex == newSelection )
+ selectedIndex = -1;
+ else
+ selectedIndex = newSelection;
+ updateState();
+ animator.invalidateLayout();
+ }
+
+ /** called on mouse move to update the hilight */
+ private function updateHilight( e : MouseEvent ) : void
+ {
+ var newHilight : Number = findItemForPosition( this.mouseX, this.mouseY );
+
+ if ( newHilight == hilightedItemIndex )
+ return;
+ hilightedItemIndex = newHilight;
+ updateState();
+ animator.invalidateLayout();
+ }
+
+ /**
+ * update the state properties of all of the items, based on
+ * the current hilighted and/or selected items
+ */
+ protected function updateState() : void
+ {
+ var stateProperty : String = getStyle( "stateProperty" );
+
+ if ( stateProperty != null )
+ {
+ var rolloverState : String = getStyle( "rolloverValue" );
+ var selectedState : String = getStyle( "selectedValue" );
+ var unselectedValue : String = getStyle( "unselectedValue" );
+
+ if ( unselectedValue == null || ( isNaN( selectedItemIndex ) && isNaN( hilightedItemIndex ) ) )
+ unselectedValue = getStyle( "defaultValue" );
+
+ for ( var i : int = 0; i < renderers.length; i++ )
+ {
+ renderers[ i ][ stateProperty ] = ( i == selectedItemIndex ) ? selectedState : ( i == hilightedItemIndex ) ? rolloverState : unselectedValue;
+ }
+ }
+ }
+
+ /**
+ * each item get scaled down based on its distance from the hliighted item. this is the equation we use
+ * to figure out how much to scale down. The basic idea is this...we have two parameters that play a part
+ * in how quickly we scale down, scaleRadius and scaleSlope. scaleRadius is the number of items on either
+ * side of the hilighted item (inclusive) that we should be able to use to scale down. scaleSlope affects
+ * how whether we scale down quickly with the first few items in the radius, or the last few items.
+ * This equation essentially does that.
+ */
+ private function calcDistanceFactor( params : FisheyeParameters, distance : Number ) : Number
+ {
+ var mult : Number = 1 / params.scaleRadius;
+ return Math.max( 0, 1 - Math.pow( distance * mult, params.scaleSlope ) );
+ }
+
+ /**
+ * populates a set of items to fit into the distance axisLength, assuming nothing is hilighted, so they
+ * all scale the same. It will attempt to scale them to match the defaultScale style */
+ protected function populateMajorAxisForDefault( pdata : Array, axis : FisheyeAxis,
+ axisLength : Number ) : FisheyeParameters
+ {
+ var vp : Number;
+ var itemCount : int = pdata.length;
+ var params : FisheyeParameters = new FisheyeParameters();
+ populateParameters( params, false );
+ var summedSpacing : Number = params.spacing * ( itemCount - 1 );
+ var sizeSum : Number = 0;
+ var pdataInst : FisheyeItem;
+
+ for ( var i : int = 0; i < itemCount; i++ )
+ sizeSum += pdata[ i ][ axis.EOM ];
+
+ if ( sizeSum > 0 )
+ {
+ var maximumMinScale : Number = ( axisLength - summedSpacing ) / sizeSum;
+ params.minScale = Math.min( params.minScale, maximumMinScale );
+ }
+ vp = 0;
+
+ for ( i = 0; i < itemCount; i++ )
+ {
+ pdataInst = pdata[ i ];
+ pdataInst.scale = params.minScale;
+ pdataInst[ axis.pos ] = vp;
+ vp += pdataInst[ axis.EOM ] * params.minScale + params.spacing;
+ }
+ return params;
+ }
+
+ /**
+ * takes the parameters used in the fisheye equation, and adjusts them as best as possible to make sure the
+ * items can fit into distance 'axisScale.' Right now it does this by scaling down the minScale parameter if necessary. That's
+ * not entirely sufficient, but it does a pretty good job. For future work: If that's not sufficient, adjust the scaleRadius, scaleSlope,
+ * and spacing parameter
+ */
+ private function adjustParameters( pdata : Array, targetIndex : Number, params : FisheyeParameters,
+ axisSize : Number, axis : FisheyeAxis ) : void
+ {
+ var itemCount : int = pdata.length;
+ var summedSpacing : Number = params.spacing * ( itemCount - 1 );
+ var maxSum : Number = 0;
+ var minSum : Number = 0;
+
+ // given the constraint:
+ // W(0) * S(0) + spacing + W(1) * S(1) + spacing + ... + W(N) * S(N) <= unscaledWidth
+ // here we adjust the numbers that go into the calculation of S(i) to fit.
+ // right now that just means adjusting minScale downward if necessary. We'll probably add some more complex heuristic later.
+ for ( var i : int = 0; i < itemCount; i++ )
+ {
+ var pdataInst : FisheyeItem = pdata[ i ];
+ var distanceFromItem : Number = Math.abs( targetIndex - i );
+ var distanceFactor : Number = calcDistanceFactor( params, distanceFromItem );
+ var maxFactor : Number = params.maxScale * distanceFactor;
+ var minFactor : Number = ( 1 - distanceFactor );
+ var itemSize : Number = pdataInst[ axis.EOM ];
+ maxSum += itemSize * maxFactor;
+ minSum += itemSize * minFactor;
+ }
+ var minScale : Number = ( minSum > 0 ) ? ( ( axisSize - summedSpacing - maxSum ) / minSum ) : 0;
+ // if we've got lots of extra space, we might calculate that we need to make our ends _larger_ to fill the space. We don't want
+ // to do that. So let's contrain it to minScale.
+ minScale = Math.min( params.minScale, minScale );
+ params.minScale = minScale;
+ }
+
+ /**
+ * populate a parameters structure from the various styles
+ */
+ private function populateParameters( params : FisheyeParameters, hilighted : Boolean ) : void
+ {
+ if ( hilighted == false )
+ {
+ params.minScale = getStyle( "defaultScale" );
+
+ if ( isNaN( params.minScale ) )
+ params.minScale = .5;
+ params.spacing = defaultSpacingWithDefault;
+ }
+ else
+ {
+ params.minScale = getStyle( "hilightMinScale" );
+
+ if ( isNaN( params.minScale ) )
+ {
+ params.minScale = getStyle( "defaultScale" );
+
+ if ( isNaN( params.minScale ) )
+ params.minScale = .5;
+ }
+ params.spacing = getStyle( "hilightSpacing" );
+
+ if ( isNaN( params.spacing ) )
+ params.spacing = defaultSpacingWithDefault;
+ }
+ params.maxScale = getStyle( "hilightMaxScale" );
+
+ if ( isNaN( params.maxScale ) )
+ params.maxScale = 1;
+ params.scaleRadius = getStyle( "hilightScaleRadius" );
+
+ if ( isNaN( params.scaleRadius ) )
+ params.scaleRadius = 2;
+ params.scaleRadius = Math.max( 1, params.scaleRadius );
+ params.scaleSlope = getStyle( "hilightScaleSlope" );
+
+ if ( isNaN( params.scaleSlope ) )
+ params.scaleSlope = .75;
+ }
+
+ /**
+ * populates a set of items to fit into the distance axisLength, assuming targetIndex is hilighted.
+ */
+ protected function populateMajorAxisFor( pdata : Array, targetIndex : Number, axisSize : Number,
+ axis : FisheyeAxis ) : FisheyeParameters
+ {
+ var vp : Number;
+ var itemCount : int = pdata.length;
+ var pdataInst : FisheyeItem;
+ var params : FisheyeParameters = new FisheyeParameters();
+ populateParameters( params, true );
+ adjustParameters( pdata, targetIndex, params, axisSize, axis );
+ vp = 0;
+
+ for ( var i : int = 0; i < itemCount; i++ )
+ {
+ pdataInst = pdata[ i ];
+ var distanceFromItem : Number = Math.abs( targetIndex - i );
+ var distanceFactor : Number = calcDistanceFactor( params, distanceFromItem );
+ var scale : Number = Math.max( 0,
+ params.minScale + ( params.maxScale - params.minScale ) * ( distanceFactor ) );
+ pdataInst[ axis.pos ] = vp;
+ pdataInst.scale = scale;
+ vp += pdataInst[ axis.EOM ] * scale + params.spacing;
+ }
+ return params;
+ }
+
+ /**
+ * given a set of scaled and laid out items, adjust them forward or backward to match the align property
+ */
+ protected function align( pdata : Array, axis : FisheyeAxis ) : void
+ {
+ var majorAlignValue : String = getStyle( axis.align );
+ var itemCount : int = pdata.length;
+ var pdataInst : FisheyeItem;
+
+ if ( itemCount == 0 )
+ return;
+
+ switch ( majorAlignValue )
+ {
+ case "right":
+ case "bottom":
+ pdataInst = pdata[ itemCount - 1 ];
+ var offset : Number = this[ axis.unscaled ] - ( pdataInst[ axis.pos ] + pdata[ itemCount - 1 ][ axis.EOM ] * pdataInst.scale );
+ for ( var i : int = 0; i < itemCount; i++ )
+ {
+ pdata[ i ][ axis.pos ] += offset;
+ }
+ break;
+ case "left":
+ case "top":
+ break;
+ case "center":
+ default:
+ var midIndex : int = Math.floor( itemCount / 2 );
+ pdataInst = pdata[ itemCount - 1 ];
+ var rightPos : Number = pdataInst[ axis.pos ] + pdataInst[ axis.EOM ] * pdataInst.scale;
+ offset = ( this[ axis.unscaled ] / 2 - ( rightPos ) / 2 );
+ for ( i = 0; i < itemCount; i++ )
+ {
+ pdata[ i ][ axis.pos ] += offset;
+ }
+ break;
+ }
+ }
+
+ /**
+ * overridden in the subclasses
+ */
+ protected function generateLayout() : void
+ {
+ }
+
+ override protected function updateDisplayList( unscaledWidth : Number, unscaledHeight : Number ) : void
+ {
+ graphics.clear();
+ graphics.moveTo( 0, 0 );
+ graphics.beginFill( 0, 0 );
+ graphics.drawRect( 0, 0, unscaledWidth, unscaledHeight );
+ // update the mask
+ mask.width = unscaledWidth;
+ mask.height = unscaledHeight;
+ animator.invalidateLayout();
+ }
+
+ override public function styleChanged( styleProp : String ) : void
+ {
+ if ( styleProp == "animationSpeed" )
+ animator.animationSpeed = getStyle( "animationSpeed" );
+ invalidateSize();
+ invalidateDisplayList();
+ animator.invalidateLayout();
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/test/resources/examples/FlexPMD115.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/parser/parser-impl/src/test/resources/examples/FlexPMD115.as b/FlexPMD/language-module/parser/parser-impl/src/test/resources/examples/FlexPMD115.as
new file mode 100644
index 0000000..ca9191c
--- /dev/null
+++ b/FlexPMD/language-module/parser/parser-impl/src/test/resources/examples/FlexPMD115.as
@@ -0,0 +1,22 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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 foo.bar
+{
+ public function baz() : void { }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/test/resources/examples/FlexPMD195.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/parser/parser-impl/src/test/resources/examples/FlexPMD195.as b/FlexPMD/language-module/parser/parser-impl/src/test/resources/examples/FlexPMD195.as
new file mode 100644
index 0000000..65ba179
--- /dev/null
+++ b/FlexPMD/language-module/parser/parser-impl/src/test/resources/examples/FlexPMD195.as
@@ -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
+{
+ import flash.display.Sprite;
+
+ public class FlexPMD195 extends Sprite {
+ public function computeJustifyAdjustment(lineArray:Array, firstLineIndex:int, numLines:int):Number
+ {
+ adj = 0;
+
+ if (numLines == 1)
+ {
+ return 0; // do nothing
+ }
+
+ // first line unchanged
+ var firstLine:IVerticalJustificationLine = lineArray[firstLineIndex];
+ var firstBaseLine:Number = getBaseline(firstLine);
+
+ // descent of the last line on the bottom of the frame
+ var lastLine:IVerticalJustificationLine = lineArray[firstLineIndex + numLines - 1];
+ var frameBottom:Number = _textFrame.compositionHeight - Number(_textFrame.effectivePaddingBottom);
+ var allowance:Number = frameBottom - getBottomOfLine(lastLine);
+ if (allowance < 0)
+ {
+ return 0; // Some text scrolled out; don't justify
+ }
+ var lastBaseLine:Number = getBaseline(lastLine);
+
+ adj = allowance/(lastBaseLine - firstBaseLine); // multiplicative factor by which the space between consecutive lines is increased
+ return adj;
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/test/resources/examples/FlexPMD62.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/parser/parser-impl/src/test/resources/examples/FlexPMD62.as b/FlexPMD/language-module/parser/parser-impl/src/test/resources/examples/FlexPMD62.as
new file mode 100644
index 0000000..9585654
--- /dev/null
+++ b/FlexPMD/language-module/parser/parser-impl/src/test/resources/examples/FlexPMD62.as
@@ -0,0 +1,35 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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.test.testy.ui.components {
+
+ import flash.display.Sprite;
+
+ public class Link extends Sprite {
+
+ protected var _linkText:String = ''; // NO PMD
+ protected var _style:String;
+
+ public function Link(text:String = '', style:String = null) // NO PMD
+ {
+ _style = style;
+ _linkText = text;
+ }
+
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/test/resources/examples/FlexPMD98.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/parser/parser-impl/src/test/resources/examples/FlexPMD98.as b/FlexPMD/language-module/parser/parser-impl/src/test/resources/examples/FlexPMD98.as
new file mode 100644
index 0000000..353395b
--- /dev/null
+++ b/FlexPMD/language-module/parser/parser-impl/src/test/resources/examples/FlexPMD98.as
@@ -0,0 +1,440 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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
+{
+ import flash.display.*;
+ import flash.events.Event;
+ import flash.text.*;
+ import flash.utils.*;
+
+ /**
+ * An app to test function call performance
+ * @author Jackson Dunstan
+ */
+ public class FunctionPerformanceTest extends Base implements IInterface
+ {
+ private function privateFunction(): void {}
+ protected function protectedFunction(): void {}
+ internal function internalFunction(): void {}
+ public function publicFunction(): void {}
+
+ private function get privateGetFunction(): int { return 0; }
+ protected function get protectedGetFunction(): int { return 0; }
+ internal function get internalGetFunction(): int { return 0; }
+ public function get publicGetFunction(): int { return 0; }
+
+ private function set privateSetFunction(val:int): void {}
+ protected function set protectedSetFunction(val:int): void {}
+ internal function set internalSetFunction(val:int): void {}
+ public function set publicSetFunction(val:int): void {}
+
+ private static function staticPrivateFunction(): void {}
+ protected static function staticProtectedFunction(): void {}
+ internal static function staticInternalFunction(): void {}
+ public static function staticPublicFunction(): void {}
+
+ override protected function overrideProtectedFunction(): void {}
+ override internal function overrideInternalFunction(): void {}
+ override public function overridePublicFunction(): void {}
+
+ final private function finalPrivateFunction(): void {}
+ final protected function finalProtectedFunction(): void {}
+ final internal function finalInternalFunction(): void {}
+ final public function finalPublicFunction(): void {}
+
+ final override protected function finalOverrideProtectedFunction(): void {}
+ final override internal function finalOverrideInternalFunction(): void {}
+ final override public function finalOverridePublicFunction(): void {}
+
+ public function interfaceFunction(): void {}
+
+ private var __logger:TextField;
+
+ /**
+ * Application entry point
+ */
+ public function FunctionPerformanceTest()
+ {
+ stage.align = StageAlign.TOP_LEFT;
+ stage.scaleMode = StageScaleMode.NO_SCALE;
+ __logger = new TextField();
+ __logger.autoSize = TextFieldAutoSize.LEFT;
+ addChild(__logger);
+
+ addEventListener(Event.ENTER_FRAME, testDynamicFunctions);
+ }
+
+ private function testDynamicFunctions(ev:Event): void
+ {
+ var beforeTime:int;
+ var i:int;
+ const NUM_ITERATIONS:int = 10000000;
+
+ function localFunction(): void {}
+ var functionVarFunction:Function = function(): void {}
+
+ beforeTime = getTimer();
+ for (i = 0; i < NUM_ITERATIONS; ++i)
+ {
+ plainFunction();
+ }
+ log("Plain: " + (getTimer()-beforeTime));
+
+ beforeTime = getTimer();
+ for (i = 0; i < NUM_ITERATIONS; ++i)
+ {
+ localFunction();
+ }
+ log("Local: " + (getTimer()-beforeTime));
+
+ beforeTime = getTimer();
+ for (i = 0; i < NUM_ITERATIONS; ++i)
+ {
+ functionVarFunction();
+ }
+ log("Function var: " + (getTimer()-beforeTime));
+
+ log("");
+
+ removeEventListener(Event.ENTER_FRAME, testDynamicFunctions);
+ addEventListener(Event.ENTER_FRAME, testMethods);
+ }
+
+ private function testMethods(ev:Event): void
+ {
+ var beforeTime:int;
+ var i:int;
+ const NUM_ITERATIONS:int = 10000000;
+
+ beforeTime = getTimer();
+ for (i = 0; i < NUM_ITERATIONS; ++i)
+ {
+ privateFunction();
+ }
+ log("Private: " + (getTimer()-beforeTime));
+
+ beforeTime = getTimer();
+ for (i = 0; i < NUM_ITERATIONS; ++i)
+ {
+ protectedFunction();
+ }
+ log("Protected: " + (getTimer()-beforeTime));
+
+ beforeTime = getTimer();
+ for (i = 0; i < NUM_ITERATIONS; ++i)
+ {
+ internalFunction();
+ }
+ log("Internal: " + (getTimer()-beforeTime));
+
+ beforeTime = getTimer();
+ for (i = 0; i < NUM_ITERATIONS; ++i)
+ {
+ publicFunction();
+ }
+ log("Public: " + (getTimer()-beforeTime));
+
+ log("");
+
+ beforeTime = getTimer();
+ for (i = 0; i < NUM_ITERATIONS; ++i)
+ {
+ this.privateFunction();
+ }
+ log("this.Private: " + (getTimer()-beforeTime));
+
+ beforeTime = getTimer();
+ for (i = 0; i < NUM_ITERATIONS; ++i)
+ {
+ this.protectedFunction();
+ }
+ log("this.Protected: " + (getTimer()-beforeTime));
+
+ beforeTime = getTimer();
+ for (i = 0; i < NUM_ITERATIONS; ++i)
+ {
+ this.internalFunction();
+ }
+ log("this.Internal: " + (getTimer()-beforeTime));
+
+ beforeTime = getTimer();
+ for (i = 0; i < NUM_ITERATIONS; ++i)
+ {
+ this.publicFunction();
+ }
+ log("this.Public: " + (getTimer()-beforeTime));
+
+ log("");
+
+ beforeTime = getTimer();
+ for (i = 0; i < NUM_ITERATIONS; ++i)
+ {
+ staticPrivateFunction();
+ }
+ log("Static private: " + (getTimer()-beforeTime));
+
+ beforeTime = getTimer();
+ for (i = 0; i < NUM_ITERATIONS; ++i)
+ {
+ staticProtectedFunction();
+ }
+ log("Static protected: " + (getTimer()-beforeTime));
+
+ beforeTime = getTimer();
+ for (i = 0; i < NUM_ITERATIONS; ++i)
+ {
+ staticInternalFunction();
+ }
+ log("Static internal: " + (getTimer()-beforeTime));
+
+ beforeTime = getTimer();
+ for (i = 0; i < NUM_ITERATIONS; ++i)
+ {
+ staticPublicFunction();
+ }
+ log("Static public: " + (getTimer()-beforeTime));
+
+ log("");
+
+ beforeTime = getTimer();
+ for (i = 0; i < NUM_ITERATIONS; ++i)
+ {
+ overrideProtectedFunction();
+ }
+ log("Override protected: " + (getTimer()-beforeTime));
+
+ beforeTime = getTimer();
+ for (i = 0; i < NUM_ITERATIONS; ++i)
+ {
+ overrideInternalFunction();
+ }
+ log("Override internal: " + (getTimer()-beforeTime));
+
+ beforeTime = getTimer();
+ for (i = 0; i < NUM_ITERATIONS; ++i)
+ {
+ overridePublicFunction();
+ }
+ log("Override public: " + (getTimer()-beforeTime));
+
+ log("");
+
+ removeEventListener(Event.ENTER_FRAME, testMethods);
+ addEventListener(Event.ENTER_FRAME, testSupersAndInterfaces);
+ }
+
+ private function testSupersAndInterfaces(ev:Event): void
+ {
+ var beforeTime:int;
+ var i:int;
+ const NUM_ITERATIONS:int = 10000000;
+
+ beforeTime = getTimer();
+ for (i = 0; i < NUM_ITERATIONS; ++i)
+ {
+ super.overrideProtectedFunction();
+ }
+ log("Super protected: " + (getTimer()-beforeTime));
+
+ beforeTime = getTimer();
+ for (i = 0; i < NUM_ITERATIONS; ++i)
+ {
+ super.overrideInternalFunction();
+ }
+ log("Super internal: " + (getTimer()-beforeTime));
+
+ beforeTime = getTimer();
+ for (i = 0; i < NUM_ITERATIONS; ++i)
+ {
+ super.overridePublicFunction();
+ }
+ log("Super public: " + (getTimer()-beforeTime));
+
+ log("");
+
+ beforeTime = getTimer();
+ for (i = 0; i < NUM_ITERATIONS; ++i)
+ {
+ interfaceFunction();
+ }
+ log("Interface direct: " + (getTimer()-beforeTime));
+
+ var inter:IInterface = this;
+ beforeTime = getTimer();
+ for (i = 0; i < NUM_ITERATIONS; ++i)
+ {
+ inter.interfaceFunction();
+ }
+ log("Interface via interface: " + (getTimer()-beforeTime));
+
+ var clazz:FunctionPerformanceTest = this;
+ beforeTime = getTimer();
+ for (i = 0; i < NUM_ITERATIONS; ++i)
+ {
+ clazz.interfaceFunction();
+ }
+ log("Interface via class: " + (getTimer()-beforeTime));
+
+ log("");
+
+ removeEventListener(Event.ENTER_FRAME, testSupersAndInterfaces);
+ addEventListener(Event.ENTER_FRAME, testGettersAndSetters);
+ }
+
+ private function testGettersAndSetters(ev:Event): void
+ {
+ var beforeTime:int;
+ var i:int;
+ const NUM_ITERATIONS:int = 10000000;
+
+ beforeTime = getTimer();
+ for (i = 0; i < NUM_ITERATIONS; ++i)
+ {
+ privateGetFunction;
+ }
+ log("Private Get: " + (getTimer()-beforeTime));
+
+ beforeTime = getTimer();
+ for (i = 0; i < NUM_ITERATIONS; ++i)
+ {
+ protectedGetFunction;
+ }
+ log("Protected Get: " + (getTimer()-beforeTime));
+
+ beforeTime = getTimer();
+ for (i = 0; i < NUM_ITERATIONS; ++i)
+ {
+ internalGetFunction;
+ }
+ log("Internal Get: " + (getTimer()-beforeTime));
+
+ beforeTime = getTimer();
+ for (i = 0; i < NUM_ITERATIONS; ++i)
+ {
+ publicGetFunction;
+ }
+ log("Public Get: " + (getTimer()-beforeTime));
+
+ log("");
+
+ beforeTime = getTimer();
+ for (i = 0; i < NUM_ITERATIONS; ++i)
+ {
+ privateSetFunction = 0;
+ }
+ log("Private Set: " + (getTimer()-beforeTime));
+
+ beforeTime = getTimer();
+ for (i = 0; i < NUM_ITERATIONS; ++i)
+ {
+ protectedSetFunction = 0;
+ }
+ log("Protected Set: " + (getTimer()-beforeTime));
+
+ beforeTime = getTimer();
+ for (i = 0; i < NUM_ITERATIONS; ++i)
+ {
+ internalSetFunction = 0;
+ }
+ log("Internal Set: " + (getTimer()-beforeTime));
+
+ beforeTime = getTimer();
+ for (i = 0; i < NUM_ITERATIONS; ++i)
+ {
+ publicSetFunction = 0;
+ }
+ log("Public Set: " + (getTimer()-beforeTime));
+
+ log("");
+
+ removeEventListener(Event.ENTER_FRAME, testGettersAndSetters);
+ addEventListener(Event.ENTER_FRAME, testFinals);
+ }
+
+ private function testFinals(ev:Event): void
+ {
+ var beforeTime:int;
+ var i:int;
+ const NUM_ITERATIONS:int = 10000000;
+
+ beforeTime = getTimer();
+ for (i = 0; i < NUM_ITERATIONS; ++i)
+ {
+ finalPrivateFunction();
+ }
+ log("Final Private: " + (getTimer()-beforeTime));
+
+ beforeTime = getTimer();
+ for (i = 0; i < NUM_ITERATIONS; ++i)
+ {
+ finalProtectedFunction();
+ }
+ log("Final Protected: " + (getTimer()-beforeTime));
+
+ beforeTime = getTimer();
+ for (i = 0; i < NUM_ITERATIONS; ++i)
+ {
+ finalInternalFunction();
+ }
+ log("Final Internal: " + (getTimer()-beforeTime));
+
+ beforeTime = getTimer();
+ for (i = 0; i < NUM_ITERATIONS; ++i)
+ {
+ finalPublicFunction();
+ }
+ log("Final Public: " + (getTimer()-beforeTime));
+
+ log("");
+
+ beforeTime = getTimer();
+ for (i = 0; i < NUM_ITERATIONS; ++i)
+ {
+ finalOverrideProtectedFunction();
+ }
+ log("Final Override protected: " + (getTimer()-beforeTime));
+
+ beforeTime = getTimer();
+ for (i = 0; i < NUM_ITERATIONS; ++i)
+ {
+ finalOverrideInternalFunction();
+ }
+ log("Final Override internal: " + (getTimer()-beforeTime));
+
+ beforeTime = getTimer();
+ for (i = 0; i < NUM_ITERATIONS; ++i)
+ {
+ finalOverridePublicFunction();
+ }
+ log("Final Override public: " + (getTimer()-beforeTime));
+
+ removeEventListener(Event.ENTER_FRAME, testFinals);
+ }
+
+ private function log(msg:*): void
+ {
+ __logger.appendText(msg + "\n");
+ }
+ }
+}
+function plainFunction(): void {}
+interface IInterface
+{
+ function interfaceFunction(): void;
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/test/resources/examples/JPEGEncoder.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/parser/parser-impl/src/test/resources/examples/JPEGEncoder.as b/FlexPMD/language-module/parser/parser-impl/src/test/resources/examples/JPEGEncoder.as
new file mode 100644
index 0000000..c3c85cc
--- /dev/null
+++ b/FlexPMD/language-module/parser/parser-impl/src/test/resources/examples/JPEGEncoder.as
@@ -0,0 +1,669 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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
+{
+ import flash.display.BitmapData;
+ import flash.utils.ByteArray;
+
+ public final class JPEGEncoder
+ {
+ // Static table initialization
+ private const ZigZag:Vector.<int> = Vector.<int>([
+ 0, 1, 5, 6,14,15,27,28,
+ 2, 4, 7,13,16,26,29,42,
+ 3, 8,12,17,25,30,41,43,
+ 9,11,18,24,31,40,44,53,
+ 10,19,23,32,39,45,52,54,
+ 20,22,33,38,46,51,55,60,
+ 21,34,37,47,50,56,59,61,
+ 35,36,48,49,57,58,62,63
+ ]);
+ private var YTable:Vector.<int> = new Vector.<int>(64, true);
+ private var UVTable:Vector.<int> = new Vector.<int>(64, true);
+ private var outputfDCTQuant:Vector.<int> = new Vector.<int>(64, true);
+ private var fdtbl_Y:Vector.<Number> = new Vector.<Number>(64, true);
+ private var fdtbl_UV:Vector.<Number> = new Vector.<Number>(64, true);
+ private var sf:int;
+
+ private const aasf:Vector.<Number> = Vector.<Number>([
+ 1.0, 1.387039845, 1.306562965, 1.175875602,
+ 1.0, 0.785694958, 0.541196100, 0.275899379
+ ]);
+
+ private var YQT:Vector.<int> = Vector.<int>([
+ 16, 11, 10, 16, 24, 40, 51, 61,
+ 12, 12, 14, 19, 26, 58, 60, 55,
+ 14, 13, 16, 24, 40, 57, 69, 56,
+ 14, 17, 22, 29, 51, 87, 80, 62,
+ 18, 22, 37, 56, 68,109,103, 77,
+ 24, 35, 55, 64, 81,104,113, 92,
+ 49, 64, 78, 87,103,121,120,101,
+ 72, 92, 95, 98,112,100,103, 99
+ ]);
+
+ private const UVQT:Vector.<int> = Vector.<int>([
+ 17, 18, 24, 47, 99, 99, 99, 99,
+ 18, 21, 26, 66, 99, 99, 99, 99,
+ 24, 26, 56, 99, 99, 99, 99, 99,
+ 47, 66, 99, 99, 99, 99, 99, 99,
+ 99, 99, 99, 99, 99, 99, 99, 99,
+ 99, 99, 99, 99, 99, 99, 99, 99,
+ 99, 99, 99, 99, 99, 99, 99, 99,
+ 99, 99, 99, 99, 99, 99, 99, 99
+ ]);
+
+ private function initQuantTables(sf:int):void
+ {
+ var i:int;
+ const I64:int = 64;
+ const I8:int = 8;
+ for (i = 0; i < I64; ++i)
+ {
+ var t:int = int((YQT[i]*sf+50)*0.01);
+ if (t < 1) {
+ t = 1;
+ } else if (t > 255) {
+ t = 255;
+ }
+ YTable[ZigZag[i]] = t;
+ }
+
+ for (i = 0; i < I64; i++)
+ {
+ var u:int = int((UVQT[i]*sf+50)*0.01);
+ if (u < 1) {
+ u = 1;
+ } else if (u > 255) {
+ u = 255;
+ }
+ UVTable[ZigZag[i]] = u;
+ }
+ i = 0;
+ for (var row:int = 0; row < I8; ++row)
+ {
+ for (var col:int = 0; col < I8; ++col)
+ {
+ fdtbl_Y[i] = (1 / (YTable [ZigZag[i]] * aasf[row] * aasf[col] * I8));
+ fdtbl_UV[i] = (1 / (UVTable[ZigZag[i]] * aasf[row] * aasf[col] * I8));
+ i++;
+ }
+ }
+ }
+
+ private var YDC_HT:Vector.<BitString>;
+ private var UVDC_HT:Vector.<BitString>;
+ private var YAC_HT:Vector.<BitString>;
+ private var UVAC_HT:Vector.<BitString>;
+
+ private function computeHuffmanTbl(nrcodes:Vector.<int>, std_table:Vector.<int>):Vector.<BitString>
+ {
+ var codevalue:int = 0;
+ var pos_in_table:int = 0;
+ var HT:Vector.<BitString> = new Vector.<BitString>(251, true);
+ var bitString:BitString;
+ for (var k:int=1; k<=16; ++k)
+ {
+ for (var j:int=1; j<=nrcodes[k]; ++j)
+ {
+ HT[std_table[pos_in_table]] = bitString = new BitString();
+ bitString.val = codevalue;
+ bitString.len = k;
+ pos_in_table++;
+ codevalue++;
+ }
+ codevalue<<=1;
+ }
+ return HT;
+ }
+
+ private var std_dc_luminance_nrcodes:Vector.<int> = Vector.<int>([0,0,1,5,1,1,1,1,1,1,0,0,0,0,0,0,0]);
+ private var std_dc_luminance_values:Vector.<int> = Vector.<int>([0,1,2,3,4,5,6,7,8,9,10,11]);
+ private var std_ac_luminance_nrcodes:Vector.<int> = Vector.<int>([0,0,2,1,3,3,2,4,3,5,5,4,4,0,0,1,0x7d]);
+ private var std_ac_luminance_values:Vector.<int> = Vector.<int>([0x01,0x02,0x03,0x00,0x04,0x11,0x05,0x12,
+ 0x21,0x31,0x41,0x06,0x13,0x51,0x61,0x07,
+ 0x22,0x71,0x14,0x32,0x81,0x91,0xa1,0x08,
+ 0x23,0x42,0xb1,0xc1,0x15,0x52,0xd1,0xf0,
+ 0x24,0x33,0x62,0x72,0x82,0x09,0x0a,0x16,
+ 0x17,0x18,0x19,0x1a,0x25,0x26,0x27,0x28,
+ 0x29,0x2a,0x34,0x35,0x36,0x37,0x38,0x39,
+ 0x3a,0x43,0x44,0x45,0x46,0x47,0x48,0x49,
+ 0x4a,0x53,0x54,0x55,0x56,0x57,0x58,0x59,
+ 0x5a,0x63,0x64,0x65,0x66,0x67,0x68,0x69,
+ 0x6a,0x73,0x74,0x75,0x76,0x77,0x78,0x79,
+ 0x7a,0x83,0x84,0x85,0x86,0x87,0x88,0x89,
+ 0x8a,0x92,0x93,0x94,0x95,0x96,0x97,0x98,
+ 0x99,0x9a,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,
+ 0xa8,0xa9,0xaa,0xb2,0xb3,0xb4,0xb5,0xb6,
+ 0xb7,0xb8,0xb9,0xba,0xc2,0xc3,0xc4,0xc5,
+ 0xc6,0xc7,0xc8,0xc9,0xca,0xd2,0xd3,0xd4,
+ 0xd5,0xd6,0xd7,0xd8,0xd9,0xda,0xe1,0xe2,
+ 0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0xea,
+ 0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,
+ 0xf9,0xfa]);
+
+ private var std_dc_chrominance_nrcodes:Vector.<int> = Vector.<int>([0,0,3,1,1,1,1,1,1,1,1,1,0,0,0,0,0]);
+ private var std_dc_chrominance_values:Vector.<int> = Vector.<int>([0,1,2,3,4,5,6,7,8,9,10,11]);
+ private var std_ac_chrominance_nrcodes:Vector.<int> = Vector.<int>([0,0,2,1,2,4,4,3,4,7,5,4,4,0,1,2,0x77]);
+ private var std_ac_chrominance_values:Vector.<int> = Vector.<int>([0x00,0x01,0x02,0x03,0x11,0x04,0x05,0x21,
+ 0x31,0x06,0x12,0x41,0x51,0x07,0x61,0x71,
+ 0x13,0x22,0x32,0x81,0x08,0x14,0x42,0x91,
+ 0xa1,0xb1,0xc1,0x09,0x23,0x33,0x52,0xf0,
+ 0x15,0x62,0x72,0xd1,0x0a,0x16,0x24,0x34,
+ 0xe1,0x25,0xf1,0x17,0x18,0x19,0x1a,0x26,
+ 0x27,0x28,0x29,0x2a,0x35,0x36,0x37,0x38,
+ 0x39,0x3a,0x43,0x44,0x45,0x46,0x47,0x48,
+ 0x49,0x4a,0x53,0x54,0x55,0x56,0x57,0x58,
+ 0x59,0x5a,0x63,0x64,0x65,0x66,0x67,0x68,
+ 0x69,0x6a,0x73,0x74,0x75,0x76,0x77,0x78,
+ 0x79,0x7a,0x82,0x83,0x84,0x85,0x86,0x87,
+ 0x88,0x89,0x8a,0x92,0x93,0x94,0x95,0x96,
+ 0x97,0x98,0x99,0x9a,0xa2,0xa3,0xa4,0xa5,
+ 0xa6,0xa7,0xa8,0xa9,0xaa,0xb2,0xb3,0xb4,
+ 0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xc2,0xc3,
+ 0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xd2,
+ 0xd3,0xd4,0xd5,0xd6,0xd7,0xd8,0xd9,0xda,
+ 0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,
+ 0xea,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,
+ 0xf9,0xfa
+ ]);
+
+ private function initHuffmanTbl():void
+ {
+ YDC_HT = computeHuffmanTbl(std_dc_luminance_nrcodes,std_dc_luminance_values);
+ UVDC_HT = computeHuffmanTbl(std_dc_chrominance_nrcodes,std_dc_chrominance_values);
+ YAC_HT = computeHuffmanTbl(std_ac_luminance_nrcodes,std_ac_luminance_values);
+ UVAC_HT = computeHuffmanTbl(std_ac_chrominance_nrcodes,std_ac_chrominance_values);
+ }
+
+ private var bitcode:Vector.<BitString> = new Vector.<BitString>(65535, true);
+ private var category:Vector.<int> = new Vector.<int>(65535, true);
+
+ private function initCategoryNumber():void
+ {
+ var nrlower:int = 1;
+ var nrupper:int = 2;
+ var bitString:BitString;
+ const I15:int = 15;
+ var pos:int;
+ for (var cat:int=1; cat<=I15; ++cat)
+ {
+ //Positive numbers
+ for (var nr:int=nrlower; nr<nrupper; ++nr)
+ {
+ pos = int(32767+nr);
+ category[pos] = cat;
+ bitcode[pos] = bitString = new BitString();
+ bitString.len = cat;
+ bitString.val = nr;
+ }
+ //Negative numbers
+ for (var nrneg:int=-(nrupper-1); nrneg<=-nrlower; ++nrneg)
+ {
+ pos = int(32767+nrneg);
+ category[pos] = cat;
+ bitcode[pos] = bitString = new BitString();
+ bitString.len = cat;
+ bitString.val = nrupper-1+nrneg;
+ }
+ nrlower <<= 1;
+ nrupper <<= 1;
+ }
+ }
+
+ // IO functions
+
+ private var byteout:ByteArray;
+ private var bytenew:int = 0;
+ private var bytepos:int = 7;
+
+ private function writeBits(bs:BitString):void
+ {
+ var value:int = bs.val;
+ var posval:int = bs.len-1;
+ while ( posval >= 0 )
+ {
+ if (value & uint(1 << posval) )
+ bytenew |= uint(1 << bytepos);
+ posval--;
+ bytepos--;
+ if (bytepos < 0)
+ {
+ if (bytenew == 0xFF)
+ {
+ byteout.writeByte(0xFF);
+ byteout.writeByte(0);
+ }
+ else byteout.writeByte(bytenew);
+ bytepos=7;
+ bytenew=0;
+ }
+ }
+ }
+
+ // DCT & quantization core
+
+ private function fDCTQuant(data:Vector.<Number>, fdtbl:Vector.<Number>):Vector.<int>
+ {
+ /* Pass 1: process rows. */
+ var dataOff:int=0;
+ var d0:Number, d1:Number, d2:Number, d3:Number, d4:Number, d5:Number, d6:Number, d7:Number;
+ var i:int;
+ const I8:int = 8;
+ const I64:int = 64;
+ for (i=0; i<I8; ++i)
+ {
+ d0 = data[int(dataOff)];
+ d1 = data[int(dataOff+1)];
+ d2 = data[int(dataOff+2)];
+ d3 = data[int(dataOff+3)];
+ d4 = data[int(dataOff+4)];
+ d5 = data[int(dataOff+5)];
+ d6 = data[int(dataOff+6)];
+ d7 = data[int(dataOff+7)];
+
+ var tmp0:Number = d0 + d7;
+ var tmp7:Number = d0 - d7;
+ var tmp1:Number = d1 + d6;
+ var tmp6:Number = d1 - d6;
+ var tmp2:Number = d2 + d5;
+ var tmp5:Number = d2 - d5;
+ var tmp3:Number = d3 + d4;
+ var tmp4:Number = d3 - d4;
+
+ /* Even part */
+ var tmp10:Number = tmp0 + tmp3; /* phase 2 */
+ var tmp13:Number = tmp0 - tmp3;
+ var tmp11:Number = tmp1 + tmp2;
+ var tmp12:Number = tmp1 - tmp2;
+
+ data[int(dataOff)] = tmp10 + tmp11; /* phase 3 */
+ data[int(dataOff+4)] = tmp10 - tmp11;
+
+ var z1:Number = (tmp12 + tmp13) * 0.707106781; /* c4 */
+ data[int(dataOff+2)] = tmp13 + z1; /* phase 5 */
+ data[int(dataOff+6)] = tmp13 - z1;
+
+ /* Odd part */
+ tmp10 = tmp4 + tmp5; /* phase 2 */
+ tmp11 = tmp5 + tmp6;
+ tmp12 = tmp6 + tmp7;
+
+ /* The rotator is modified from fig 4-8 to avoid extra negations. */
+ var z5:Number = (tmp10 - tmp12) * 0.382683433; /* c6 */
+ var z2:Number = 0.541196100 * tmp10 + z5; /* c2-c6 */
+ var z4:Number = 1.306562965 * tmp12 + z5; /* c2+c6 */
+ var z3:Number = tmp11 * 0.707106781; /* c4 */
+
+ var z11:Number = tmp7 + z3; /* phase 5 */
+ var z13:Number = tmp7 - z3;
+
+ data[int(dataOff+5)] = z13 + z2; /* phase 6 */
+ data[int(dataOff+3)] = z13 - z2;
+ data[int(dataOff+1)] = z11 + z4;
+ data[int(dataOff+7)] = z11 - z4;
+
+ dataOff += 8; /* advance pointer to next row */
+ }
+
+ /* Pass 2: process columns. */
+ dataOff = 0;
+ for (i=0; i<I8; ++i)
+ {
+ d0 = data[int(dataOff)];
+ d1 = data[int(dataOff + 8)];
+ d2 = data[int(dataOff + 16)];
+ d3 = data[int(dataOff + 24)];
+ d4 = data[int(dataOff + 32)];
+ d5 = data[int(dataOff + 40)];
+ d6 = data[int(dataOff + 48)];
+ d7 = data[int(dataOff + 56)];
+
+ var tmp0p2:Number = d0 + d7;
+ var tmp7p2:Number = d0 - d7;
+ var tmp1p2:Number = d1 + d6;
+ var tmp6p2:Number = d1 - d6;
+ var tmp2p2:Number = d2 + d5;
+ var tmp5p2:Number = d2 - d5;
+ var tmp3p2:Number = d3 + d4;
+ var tmp4p2:Number = d3 - d4;
+
+ /* Even part */
+ var tmp10p2:Number = tmp0p2 + tmp3p2; /* phase 2 */
+ var tmp13p2:Number = tmp0p2 - tmp3p2;
+ var tmp11p2:Number = tmp1p2 + tmp2p2;
+ var tmp12p2:Number = tmp1p2 - tmp2p2;
+
+ data[int(dataOff)] = tmp10p2 + tmp11p2; /* phase 3 */
+ data[int(dataOff+32)] = tmp10p2 - tmp11p2;
+
+ var z1p2:Number = (tmp12p2 + tmp13p2) * 0.707106781; /* c4 */
+ data[int(dataOff+16)] = tmp13p2 + z1p2; /* phase 5 */
+ data[int(dataOff+48)] = tmp13p2 - z1p2;
+
+ /* Odd part */
+ tmp10p2 = tmp4p2 + tmp5p2; /* phase 2 */
+ tmp11p2 = tmp5p2 + tmp6p2;
+ tmp12p2 = tmp6p2 + tmp7p2;
+
+ /* The rotator is modified from fig 4-8 to avoid extra negations. */
+ var z5p2:Number = (tmp10p2 - tmp12p2) * 0.382683433; /* c6 */
+ var z2p2:Number = 0.541196100 * tmp10p2 + z5p2; /* c2-c6 */
+ var z4p2:Number = 1.306562965 * tmp12p2 + z5p2; /* c2+c6 */
+ var z3p2:Number= tmp11p2 * 0.707106781; /* c4 */
+
+ var z11p2:Number = tmp7p2 + z3p2; /* phase 5 */
+ var z13p2:Number = tmp7p2 - z3p2;
+
+ data[int(dataOff+40)] = z13p2 + z2p2; /* phase 6 */
+ data[int(dataOff+24)] = z13p2 - z2p2;
+ data[int(dataOff+ 8)] = z11p2 + z4p2;
+ data[int(dataOff+56)] = z11p2 - z4p2;
+
+ dataOff++; /* advance pointer to next column */
+ }
+
+ // Quantize/descale the coefficients
+ var fDCTQuant:Number;
+ for (i=0; i<I64; ++i)
+ {
+ // Apply the quantization and scaling factor & Round to nearest integer
+ fDCTQuant = data[int(i)]*fdtbl[int(i)];
+ outputfDCTQuant[int(i)] = (fDCTQuant > 0.0) ? int(fDCTQuant + 0.5) : int(fDCTQuant - 0.5);
+ }
+ return outputfDCTQuant;
+ }
+
+ // Chunk writing
+ private function writeAPP0():void
+ {
+ byteout.writeShort(0xFFE0); // marker
+ byteout.writeShort(16); // length
+ byteout.writeByte(0x4A); // J
+ byteout.writeByte(0x46); // F
+ byteout.writeByte(0x49); // I
+ byteout.writeByte(0x46); // F
+ byteout.writeByte(0); // = "JFIF",'\0'
+ byteout.writeByte(1); // versionhi
+ byteout.writeByte(1); // versionlo
+ byteout.writeByte(0); // xyunits
+ byteout.writeShort(1); // xdensity
+ byteout.writeShort(1); // ydensity
+ byteout.writeByte(0); // thumbnwidth
+ byteout.writeByte(0); // thumbnheight
+ }
+
+ private function writeSOF0(width:int, height:int):void
+ {
+ byteout.writeShort(0xFFC0); // marker
+ byteout.writeShort(17); // length, truecolor YUV JPG
+ byteout.writeByte(8); // precision
+ byteout.writeShort(height);
+ byteout.writeShort(width);
+ byteout.writeByte(3); // nrofcomponents
+ byteout.writeByte(1); // IdY
+ byteout.writeByte(0x11); // HVY
+ byteout.writeByte(0); // QTY
+ byteout.writeByte(2); // IdU
+ byteout.writeByte(0x11); // HVU
+ byteout.writeByte(1); // QTU
+ byteout.writeByte(3); // IdV
+ byteout.writeByte(0x11); // HVV
+ byteout.writeByte(1); // QTV
+ }
+
+ private function writeDQT():void
+ {
+ byteout.writeShort(0xFFDB); // marker
+ byteout.writeShort(132); // length
+ byteout.writeByte(0);
+
+ var i:int;
+ const I64:int = 64;
+ for (i=0; i<I64; ++i)
+ byteout.writeByte(YTable[i]);
+
+ byteout.writeByte(1);
+
+ for (i=0; i<I64; ++i)
+ byteout.writeByte(UVTable[i]);
+ }
+
+ private function writeDHT():void
+ {
+ byteout.writeShort(0xFFC4); // marker
+ byteout.writeShort(0x01A2); // length
+
+ byteout.writeByte(0); // HTYDCinfo
+ var i:int;
+ const I11:int = 11;
+ const I16:int = 16;
+ const I161:int = 161;
+ for (i=0; i<I16; ++i)
+ byteout.writeByte(std_dc_luminance_nrcodes[int(i+1)]);
+
+ for (i=0; i<=I11; ++i)
+ byteout.writeByte(std_dc_luminance_values[int(i)]);
+
+ byteout.writeByte(0x10); // HTYACinfo
+
+ for (i=0; i<I16; ++i)
+ byteout.writeByte(std_ac_luminance_nrcodes[int(i+1)]);
+
+ for (i=0; i<=I161; ++i)
+ byteout.writeByte(std_ac_luminance_values[int(i)]);
+
+ byteout.writeByte(1); // HTUDCinfo
+
+ for (i=0; i<I16; ++i)
+ byteout.writeByte(std_dc_chrominance_nrcodes[int(i+1)]);
+
+ for (i=0; i<=I11; ++i)
+ byteout.writeByte(std_dc_chrominance_values[int(i)]);
+
+ byteout.writeByte(0x11); // HTUACinfo
+
+ for (i=0; i<I16; ++i)
+ byteout.writeByte(std_ac_chrominance_nrcodes[int(i+1)]);
+
+ for (i=0; i<=I161; ++i)
+ byteout.writeByte(std_ac_chrominance_values[int(i)]);
+ }
+
+ private function writeSOS():void
+ {
+ byteout.writeShort(0xFFDA); // marker
+ byteout.writeShort(12); // length
+ byteout.writeByte(3); // nrofcomponents
+ byteout.writeByte(1); // IdY
+ byteout.writeByte(0); // HTY
+ byteout.writeByte(2); // IdU
+ byteout.writeByte(0x11); // HTU
+ byteout.writeByte(3); // IdV
+ byteout.writeByte(0x11); // HTV
+ byteout.writeByte(0); // Ss
+ byteout.writeByte(0x3f); // Se
+ byteout.writeByte(0); // Bf
+ }
+
+ // Core processing
+ internal var DU:Vector.<int> = new Vector.<int>(64, true);
+
+ private function processDU(CDU:Vector.<Number>, fdtbl:Vector.<Number>, DC:Number, HTDC:Vector.<BitString>, HTAC:Vector.<BitString>):Number
+ {
+ var EOB:BitString = HTAC[0x00];
+ var M16zeroes:BitString = HTAC[0xF0];
+ var pos:int;
+ const I16:int = 16;
+ const I63:int = 63;
+ const I64:int = 64;
+ var DU_DCT:Vector.<int> = fDCTQuant(CDU, fdtbl);
+ //ZigZag reorder
+ for (var j:int=0;j<I64;++j) {
+ DU[ZigZag[j]]=DU_DCT[j];
+ }
+ var Diff:int = DU[0] - DC; DC = DU[0];
+ //Encode DC
+ if (Diff==0) {
+ writeBits(HTDC[0]); // Diff might be 0
+ } else {
+ pos = int(32767+Diff);
+ writeBits(HTDC[category[pos]]);
+ writeBits(bitcode[pos]);
+ }
+ //Encode ACs
+ const end0pos:int = 63;
+ for (; (end0pos>0)&&(DU[end0pos]==0); end0pos--) {};
+ //end0pos = first element in reverse order !=0
+ if ( end0pos == 0) {
+ writeBits(EOB);
+ return DC;
+ }
+ var i:int = 1;
+ var lng:int;
+ while ( i <= end0pos ) {
+ var startpos:int = i;
+ for (; (DU[i]==0) && (i<=end0pos); ++i) {}
+ var nrzeroes:int = i-startpos;
+ if ( nrzeroes >= I16 ) {
+ lng = nrzeroes>>4;
+ for (var nrmarker:int=1; nrmarker <= lng; ++nrmarker)
+ writeBits(M16zeroes);
+ nrzeroes = int(nrzeroes&0xF);
+ }
+ pos = int(32767+DU[i]);
+ writeBits(HTAC[int((nrzeroes<<4)+category[pos])]);
+ writeBits(bitcode[pos]);
+ i++;
+ }
+ if ( end0pos != I63 ) {
+ writeBits(EOB);
+ }
+ return DC;
+ }
+
+ private var YDU:Vector.<Number> = new Vector.<Number>(64, true);
+ private var UDU:Vector.<Number> = new Vector.<Number>(64, true);
+ private var VDU:Vector.<Number> = new Vector.<Number>(64, true);
+
+ private function RGB2YUV(img:BitmapData, xpos:int, ypos:int):void
+ {
+ var pos:int=0;
+ const I8:int = 8;
+ for (var y:int=0; y<I8; ++y) {
+ for (var x:int=0; x<I8; ++x) {
+ var P:uint = img.getPixel32(xpos+x,ypos+y);
+ var R:int = (P>>16)&0xFF;
+ var G:int = (P>> 8)&0xFF;
+ var B:int = (P )&0xFF;
+ YDU[int(pos)]=((( 0.29900)*R+( 0.58700)*G+( 0.11400)*B))-0x80;
+ UDU[int(pos)]=(((-0.16874)*R+(-0.33126)*G+( 0.50000)*B));
+ VDU[int(pos)]=((( 0.50000)*R+(-0.41869)*G+(-0.08131)*B));
+ ++pos;
+ }
+ }
+ }
+
+ public function JPEGEncoder(quality:int=50)
+ {
+ if (quality <= 0)
+ quality = 1;
+
+ if (quality > 100)
+ quality = 100;
+
+ sf = quality < 50 ? int(5000 / quality) : int(200 - (quality<<1));
+ init();
+ }
+
+ private function init():void
+ {
+ ZigZag.fixed = true;
+ aasf.fixed = true;
+ YQT.fixed = true;
+ UVQT.fixed = true;
+ std_ac_chrominance_nrcodes.fixed = true;
+ std_ac_chrominance_values.fixed = true;
+ std_ac_luminance_nrcodes.fixed = true;
+ std_ac_luminance_values.fixed = true;
+ std_dc_chrominance_nrcodes.fixed = true;
+ std_dc_chrominance_values.fixed = true;
+ std_dc_luminance_nrcodes.fixed = true;
+ std_dc_luminance_values.fixed = true;
+ // Create tables
+ initHuffmanTbl();
+ initCategoryNumber();
+ initQuantTables(sf);
+ }
+
+ public function encode(image:BitmapData):ByteArray
+ {
+ // Initialize bit writer
+ byteout = new ByteArray();
+
+ bytenew=0;
+ bytepos=7;
+
+ // Add JPEG headers
+ byteout.writeShort(0xFFD8); // SOI
+ writeAPP0();
+ writeDQT();
+ writeSOF0(image.width,image.height);
+ writeDHT();
+ writeSOS();
+
+ // Encode 8x8 macroblocks
+ var DCY:Number=0;
+ var DCU:Number=0;
+ var DCV:Number=0;
+ bytenew=0;
+ bytepos=7;
+
+ var width:int = image.width;
+ var height:int = image.height;
+
+ for (var ypos:int=0; ypos<height; ypos+=8)
+ {
+ for (var xpos:int=0; xpos<width; xpos+=8)
+ {
+ RGB2YUV(image, xpos, ypos);
+ DCY = processDU(YDU, fdtbl_Y, DCY, YDC_HT, YAC_HT);
+ DCU = processDU(UDU, fdtbl_UV, DCU, UVDC_HT, UVAC_HT);
+ DCV = processDU(VDU, fdtbl_UV, DCV, UVDC_HT, UVAC_HT);
+ }
+ }
+
+ // Do the bit alignment of the EOI marker
+ if ( bytepos >= 0 )
+ {
+ var fillbits:BitString = new BitString();
+ fillbits.len = bytepos+1;
+ fillbits.val = (1<<(bytepos+1))-1;
+ writeBits(fillbits);
+ }
+ byteout.writeShort(0xFFD9); //EOI
+ return byteout;
+ }
+ }
+}
+
+final class BitString
+{
+ public var len:int = 0;
+ public var val:int = 0;
+}
\ No newline at end of file
[05/24] git commit: [flex-utilities]
[refs/heads/feature/pmd-5.2-language-module] - Initial commit of the PMD
language module for Apache Flex
Posted by cd...@apache.org.
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/PngEncoder.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/PngEncoder.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/PngEncoder.as
new file mode 100644
index 0000000..f11822b
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/PngEncoder.as
@@ -0,0 +1,617 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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 org.encoding
+{
+ import flash.geom.*;
+ import flash.display.*;
+ import flash.utils.*;
+
+ public final class JPEGEncoder
+ {
+
+ // Static table initialization
+
+ internal var DU:Array = new Array(64);
+
+ private var ZigZag:Array = [
+ 0, 1, 5, 6,14,15,27,28,
+ 2, 4, 7,13,16,26,29,42,
+ 3, 8,12,17,25,30,41,43,
+ 9,11,18,24,31,40,44,53,
+ 10,19,23,32,39,45,52,54,
+ 20,22,33,38,46,51,55,60,
+ 21,34,37,47,50,56,59,61,
+ 35,36,48,49,57,58,62,63
+ ];
+
+ private var YTable:Array = new Array(64);
+ private var UVTable:Array = new Array(64);
+ private var fdtbl_Y:Array = new Array(64);
+ private var fdtbl_UV:Array = new Array(64);
+ private var YDC_HT:Array;
+ private var UVDC_HT:Array;
+ private var YAC_HT:Array;
+ private var UVAC_HT:Array;
+ private var std_dc_luminance_nrcodes:Array = [0,0,1,5,1,1,1,1,1,1,0,0,0,0,0,0,0];
+ private var std_dc_luminance_values:Array = [0,1,2,3,4,5,6,7,8,9,10,11];
+ private var std_ac_luminance_nrcodes:Array = [0,0,2,1,3,3,2,4,3,5,5,4,4,0,0,1,0x7d];
+ private var std_ac_luminance_values:Array = [
+ 0x01,0x02,0x03,0x00,0x04,0x11,0x05,0x12,
+ 0x21,0x31,0x41,0x06,0x13,0x51,0x61,0x07,
+ 0x22,0x71,0x14,0x32,0x81,0x91,0xa1,0x08,
+ 0x23,0x42,0xb1,0xc1,0x15,0x52,0xd1,0xf0,
+ 0x24,0x33,0x62,0x72,0x82,0x09,0x0a,0x16,
+ 0x17,0x18,0x19,0x1a,0x25,0x26,0x27,0x28,
+ 0x29,0x2a,0x34,0x35,0x36,0x37,0x38,0x39,
+ 0x3a,0x43,0x44,0x45,0x46,0x47,0x48,0x49,
+ 0x4a,0x53,0x54,0x55,0x56,0x57,0x58,0x59,
+ 0x5a,0x63,0x64,0x65,0x66,0x67,0x68,0x69,
+ 0x6a,0x73,0x74,0x75,0x76,0x77,0x78,0x79,
+ 0x7a,0x83,0x84,0x85,0x86,0x87,0x88,0x89,
+ 0x8a,0x92,0x93,0x94,0x95,0x96,0x97,0x98,
+ 0x99,0x9a,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,
+ 0xa8,0xa9,0xaa,0xb2,0xb3,0xb4,0xb5,0xb6,
+ 0xb7,0xb8,0xb9,0xba,0xc2,0xc3,0xc4,0xc5,
+ 0xc6,0xc7,0xc8,0xc9,0xca,0xd2,0xd3,0xd4,
+ 0xd5,0xd6,0xd7,0xd8,0xd9,0xda,0xe1,0xe2,
+ 0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0xea,
+ 0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,
+ 0xf9,0xfa
+ ];
+
+ private var std_dc_chrominance_nrcodes:Array = [0,0,3,1,1,1,1,1,1,1,1,1,0,0,0,0,0];
+ private var std_dc_chrominance_values:Array = [0,1,2,3,4,5,6,7,8,9,10,11];
+ private var std_ac_chrominance_nrcodes:Array = [0,0,2,1,2,4,4,3,4,7,5,4,4,0,1,2,0x77];
+ private var std_ac_chrominance_values:Array = [
+ 0x00,0x01,0x02,0x03,0x11,0x04,0x05,0x21,
+ 0x31,0x06,0x12,0x41,0x51,0x07,0x61,0x71,
+ 0x13,0x22,0x32,0x81,0x08,0x14,0x42,0x91,
+ 0xa1,0xb1,0xc1,0x09,0x23,0x33,0x52,0xf0,
+ 0x15,0x62,0x72,0xd1,0x0a,0x16,0x24,0x34,
+ 0xe1,0x25,0xf1,0x17,0x18,0x19,0x1a,0x26,
+ 0x27,0x28,0x29,0x2a,0x35,0x36,0x37,0x38,
+ 0x39,0x3a,0x43,0x44,0x45,0x46,0x47,0x48,
+ 0x49,0x4a,0x53,0x54,0x55,0x56,0x57,0x58,
+ 0x59,0x5a,0x63,0x64,0x65,0x66,0x67,0x68,
+ 0x69,0x6a,0x73,0x74,0x75,0x76,0x77,0x78,
+ 0x79,0x7a,0x82,0x83,0x84,0x85,0x86,0x87,
+ 0x88,0x89,0x8a,0x92,0x93,0x94,0x95,0x96,
+ 0x97,0x98,0x99,0x9a,0xa2,0xa3,0xa4,0xa5,
+ 0xa6,0xa7,0xa8,0xa9,0xaa,0xb2,0xb3,0xb4,
+ 0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xc2,0xc3,
+ 0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xd2,
+ 0xd3,0xd4,0xd5,0xd6,0xd7,0xd8,0xd9,0xda,
+ 0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,
+ 0xea,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,
+ 0xf9,0xfa
+ ];
+ private var bitcode:Array = new Array(65535);
+ private var category:Array = new Array(65535);
+ private var byteout:ByteArray;
+ private var bytenew:int = 0;
+ private var bytepos:int = 7;
+ private var YDU:Array = new Array(64);
+ private var UDU:Array = new Array(64);
+ private var VDU:Array = new Array(64);
+
+ public function JPEGEncoder(quality:Number = 50)
+ {
+ if (quality <= 0) {
+ quality = 1;
+ }
+ if (quality > 100) {
+ quality = 100;
+ }
+ var sff:int = 0;
+ if (quality < 50) {
+ sff = int(5000 / quality);
+ } else {
+ sff = int(200 - quality*2);
+ }
+ // Create tables
+ initHuffmanTbl();
+ initCategoryNumber();
+ initQuantTables(sff);
+ }
+
+ public function encode(image:BitmapData):ByteArray
+ {
+ // Initialize bit writer
+ byteout = new ByteArray();
+ bytenew=0;
+ bytepos=7;
+
+ // Add JPEG headers
+ writeWord(0xFFD8); // SOI
+ writeAPP0();
+ writeDQT();
+ writeSOF0(image.width,image.height);
+ writeDHT();
+ writeSOS();
+
+ // Encode 8x8 macroblocks
+ var DCY:Number=0;
+ var DCU:Number=0;
+ var DCV:Number=0;
+ bytenew=0;
+ bytepos=7;
+ for (var ypos:int=0; ypos<image.height; ypos+=8) {
+ for (var xpos:int=0; xpos<image.width; xpos+=8) {
+ RGB2YUV(image, xpos, ypos);
+ DCY = processDU(YDU, fdtbl_Y, DCY, YDC_HT, YAC_HT);
+ DCU = processDU(UDU, fdtbl_UV, DCU, UVDC_HT, UVAC_HT);
+ return DCV = processDU(VDU, fdtbl_UV, DCV, UVDC_HT, UVAC_HT);
+ }
+ }
+
+ // Do the bit alignment of the EOI marker
+ if ( bytepos >= 0 ) {
+ var fillbits:BitString = new BitString();
+ fillbits.len = bytepos+1;
+ fillbits.val = (1<<(bytepos+1))-1;
+ writeBits(fillbits);
+ }
+
+ writeWord(0xFFD9); //EOI
+ return byteout;
+ }
+
+ private function initQuantTables(sf:int):void
+ {
+ var YQT:Array = [
+ 16, 11, 10, 16, 24, 40, 51, 61,
+ 12, 12, 14, 19, 26, 58, 60, 55,
+ 14, 13, 16, 24, 40, 57, 69, 56,
+ 14, 17, 22, 29, 51, 87, 80, 62,
+ 18, 22, 37, 56, 68,109,103, 77,
+ 24, 35, 55, 64, 81,104,113, 92,
+ 49, 64, 78, 87,103,121,120,101,
+ 72, 92, 95, 98,112,100,103, 99
+ ];
+ for (var i:int = 0; i < 64; i++) {
+ var ttt:Number = Math.floor((YQT[i]*sf+50)/100);
+ if (ttt < 1) {
+ ttt = 1;
+ } else if (ttt > 255) {
+ ttt = 255;
+ }
+ YTable[ZigZag[i]] = ttt;
+ }
+ var UVQT:Array = [
+ 17, 18, 24, 47, 99, 99, 99, 99,
+ 18, 21, 26, 66, 99, 99, 99, 99,
+ 24, 26, 56, 99, 99, 99, 99, 99,
+ 47, 66, 99, 99, 99, 99, 99, 99,
+ 99, 99, 99, 99, 99, 99, 99, 99,
+ 99, 99, 99, 99, 99, 99, 99, 99,
+ 99, 99, 99, 99, 99, 99, 99, 99,
+ 99, 99, 99, 99, 99, 99, 99, 99
+ ];
+ for (var j:int = 0; j < 64; j++) {
+ var uuu:Number = Math.floor((UVQT[j]*sf+50)/100);
+ if (uuu < 1) {
+ uuu = 1;
+ } else if (uuu > 255) {
+ uuu = 255;
+ }
+ UVTable[ZigZag[j]] = uuu;
+ }
+ var aasf:Array = [
+ 1.0, 1.387039845, 1.306562965, 1.175875602,
+ 1.0, 0.785694958, 0.541196100, 0.275899379
+ ];
+ var kkk:int = 0;
+ for (var row:int = 0; row < 8; row++)
+ {
+ for (var col:int = 0; col < 8; col++)
+ {
+ fdtbl_Y[kkk] = (1.0 / (YTable [ZigZag[kkk]] * aasf[row] * aasf[col] * 8.0));
+ fdtbl_UV[kkk] = (1.0 / (UVTable[ZigZag[kkk]] * aasf[row] * aasf[col] * 8.0));
+ kkk++;
+ }
+ }
+ }
+
+ private function computeHuffmanTbl(nrcodes:Array, std_table:Array):Array
+ {
+ var codevalue:int = 0;
+ var pos_in_table:int = 0;
+ var HTT:Array = new Array();
+ for (var k:int=1; k<HTT16; k++) {
+ for (var j:int=1; j<=nrcodes[k]; j++) {
+ HTT[std_table[pos_in_table]] = new BitString();
+ HTT[std_table[pos_in_table]].val = codevalue;
+ HTT[std_table[pos_in_table]].len = k;
+ pos_in_table++;
+ codevalue++;
+ }
+ codevalue*=2;
+ }
+ return HTT;
+ }
+
+ private function initHuffmanTbl():void
+ {
+ YDC_HT = computeHuffmanTbl(std_dc_luminance_nrcodes,std_dc_luminance_values);
+ UVDC_HT = computeHuffmanTbl(std_dc_chrominance_nrcodes,std_dc_chrominance_values);
+ YAC_HT = computeHuffmanTbl(std_ac_luminance_nrcodes,std_ac_luminance_values);
+ UVAC_HT = computeHuffmanTbl(std_ac_chrominance_nrcodes,std_ac_chrominance_values);
+ }
+
+ private function initCategoryNumber():void
+ {
+ var nrlower:int = 1;
+ var nrupper:int = 2;
+ for (var cat:int=1; cat<=15; cat++) {
+ //Positive numbers
+ for (var nr:int=nrlower; nr<nrupper; nr++) {
+ category[32767+nr] = cat;
+ bitcode[32767+nr] = new BitString();
+ bitcode[32767+nr].len = cat;
+ bitcode[32767+nr].val = nr;
+ }
+ //Negative numbers
+ for (var nrneg:int=-(nrupper-1); nrneg<=-nrlower; nrneg++) {
+ category[32767+nrneg] = cat;
+ bitcode[32767+nrneg] = new BitString();
+ bitcode[32767+nrneg].len = cat;
+ bitcode[32767+nrneg].val = nrupper-1+nrneg;
+ }
+ nrlower <<= 1;
+ nrupper <<= 1;
+ }
+ }
+
+ private function writeBits(bs:BitString):void
+ {
+ var value:int = bs.val;
+ var posval:int = bs.len-1;
+ while ( posval >= 0 ) {
+ if (value & uint(1 << posval) ) {
+ bytenew |= uint(1 << bytepos);
+ }
+ posval--;
+ bytepos--;
+ if (bytepos < 0) {
+ if (bytenew == 0xFF) {
+ writeByte(0xFF);
+ writeByte(0);
+ }
+ else {
+ writeByte(bytenew);
+ }
+ bytepos=7;
+ bytenew=0;
+ }
+ }
+ }
+
+ private function writeByte(value:int):void
+ {
+ byteout.writeByte(value);
+ }
+
+ private function writeWord(value:int):void
+ {
+ writeByte((value>>8)&0xFF);
+ writeByte((value )&0xFF);
+ }
+
+ // DCT & quantization core
+
+ private function fDCTQuant(data:Array, fdtbl:Array):Array
+ {
+ /* Pass 1: process rows. */
+ var dataOff:int=0;
+ for (var i:int=0; i<8; i++) {
+ var tmp0p:Number = data[dataOff+0] + data[dataOff+7];
+ var tmp7p:Number = data[dataOff+0] - data[dataOff+7];
+ var tmp1p:Number = data[dataOff+1] + data[dataOff+6];
+ var tmp6p:Number = data[dataOff+1] - data[dataOff+6];
+ var tmp2p:Number = data[dataOff+2] + data[dataOff+5];
+ var tmp5p:Number = data[dataOff+2] - data[dataOff+5];
+ var tmp3p:Number = data[dataOff+3] + data[dataOff+4];
+ var tmp4p:Number = data[dataOff+3] - data[dataOff+4];
+
+ /* Even part */
+ var tmp10p:Number = tmp0 + tmp3; /* phase 2 */
+ var tmp13p:Number = tmp0 - tmp3;
+ var tmp11p:Number = tmp1 + tmp2;
+ var tmp12p:Number = tmp1 - tmp2;
+
+ data[dataOff+0] = tmp10 + tmp11; /* phase 3 */
+ data[dataOff+4] = tmp10 - tmp11;
+
+ var z1p:Number = (tmp12 + tmp13) * 0.707106781; /* c4 */
+ data[dataOff+2] = tmp13 + z1; /* phase 5 */
+ data[dataOff+6] = tmp13 - z1;
+
+ /* Odd part */
+ tmp10 = tmp4 + tmp5; /* phase 2 */
+ tmp11 = tmp5 + tmp6;
+ tmp12 = tmp6 + tmp7;
+
+ /* The rotator is modified from fig 4-8 to avoid extra negations. */
+ var zz5p:Number = (tmp10 - tmp12) * 0.382683433; /* c6 */
+ var zz2p:Number = 0.541196100 * tmp10 + zz5; /* c2-c6 */
+ var zz4p:Number = 1.306562965 * tmp12 + zz5; /* c2+c6 */
+ var zz3p:Number = tmp11 * 0.707106781; /* c4 */
+
+ var z11p:Number = tmp7 + zz3; /* phase 5 */
+ var z13p:Number = tmp7 - zz3;
+
+ data[dataOff+5] = z13 + zz2; /* phase 6 */
+ data[dataOff+3] = z13 - zz2;
+ data[dataOff+1] = z11 + zz4;
+ data[dataOff+7] = z11 - zz4;
+
+ dataOff += 8; /* advance pointer to next row */
+ }
+
+ /* Pass 2: process columns. */
+ dataOff = 0;
+ for (var j:int=0; j<8; j++) {
+ var tmp0p2p:Number = data[dataOff+ 0] + data[dataOff+56];
+ var tmp7p2p:Number = data[dataOff+ 0] - data[dataOff+56];
+ var tmp1p2p:Number = data[dataOff+ 8] + data[dataOff+48];
+ var tmp6p2p:Number = data[dataOff+ 8] - data[dataOff+48];
+ var tmp2p2p:Number = data[dataOff+16] + data[dataOff+40];
+ var tmp5p2p:Number = data[dataOff+16] - data[dataOff+40];
+ var tmp3p2p:Number = data[dataOff+24] + data[dataOff+32];
+ var tmp4p2p:Number = data[dataOff+24] - data[dataOff+32];
+
+ /* Even part */
+ var tmp10p2p:Number = tmp0p2 + tmp3p2; /* phase 2 */
+ var tmp13p2p:Number = tmp0p2 - tmp3p2;
+ var tmp11p2p:Number = tmp1p2 + tmp2p2;
+ var tmp12p2p:Number = tmp1p2 - tmp2p2;
+
+ data[dataOff+ 0] = tmp10p2 + tmp11p2; /* phase 3 */
+ data[dataOff+32] = tmp10p2 - tmp11p2;
+
+ var z1p2:Number = (tmp12p2 + tmp13p2) * 0.707106781; /* c4 */
+ data[dataOff+16] = tmp13p2 + z1p2; /* phase 5 */
+ data[dataOff+48] = tmp13p2 - z1p2;
+
+ /* Odd part */
+ tmp10p2 = tmp4p2 + tmp5p2; /* phase 2 */
+ tmp11p2 = tmp5p2 + tmp6p2;
+ tmp12p2 = tmp6p2 + tmp7p2;
+
+ /* The rotator is modified from fig 4-8 to avoid extra negations. */
+ var z5p2p:Number = (tmp10p2 - tmp12p2) * 0.382683433; /* c6 */
+ var z2p2p:Number = 0.541196100 * tmp10p2 + z5p2; /* c2-c6 */
+ var z4p2p:Number = 1.306562965 * tmp12p2 + z5p2; /* c2+c6 */
+ var z3p2p:Number= tmp11p2 * 0.707106781; /* c4 */
+
+ var z11p2p:Number = tmp7p2 + z3p2; /* phase 5 */
+ var z13p2p:Number = tmp7p2 - z3p2;
+
+ data[dataOff+40] = z13p2 + z2p2; /* phase 6 */
+ data[dataOff+24] = z13p2 - z2p2;
+ data[dataOff+ 8] = z11p2 + z4p2;
+ data[dataOff+56] = z11p2 - z4p2;
+
+ dataOff++; /* advance pointer to next column */
+ }
+
+ // Quantize/descale the coefficients
+ for (var k:int=0; k<64; k++) {
+ // Apply the quantization and scaling factor & Round to nearest integer
+ data[k] = Math.round((data[k]*fdtbl[k]));
+ }
+ return data;
+ }
+
+ // Chunk writing
+
+ private function writeAPP0():void
+ {
+ writeWord(0xFFE0); // marker
+ writeWord(16); // length
+ writeByte(0x4A); // J
+ writeByte(0x46); // F
+ writeByte(0x49); // I
+ writeByte(0x46); // F
+ writeByte(0); // = "JFIF",'\0'
+ writeByte(1); // versionhi
+ writeByte(1); // versionlo
+ writeByte(0); // xyunits
+ writeWord(1); // xdensity
+ writeWord(1); // ydensity
+ writeByte(0); // thumbnwidth
+ writeByte(0); // thumbnheight
+ }
+
+ private function writeSOF0(width:int, height:int):void
+ {
+ writeWord(0xFFC0); // marker
+ writeWord(17); // length, truecolor YUV JPG
+ writeByte(8); // precision
+ writeWord(height);
+ writeWord(width);
+ writeByte(3); // nrofcomponents
+ writeByte(1); // IdY
+ writeByte(0x11); // HVY
+ writeByte(0); // QTY
+ writeByte(2); // IdU
+ writeByte(0x11); // HVU
+ writeByte(1); // QTU
+ writeByte(3); // IdV
+ writeByte(0x11); // HVV
+ writeByte(1); // QTV
+ }
+
+ private function writeDQT():void
+ {
+ writeWord(0xFFDB); // marker
+ writeWord(132); // length
+ writeByte(0);
+ for (var i:int=0; i<64; i++) {
+ writeByte(YTable[i]);
+ }
+ writeByte(1);
+ for (var j:int=0; j<64; j++) {
+ writeByte(UVTable[j]);
+ }
+ }
+
+ private function writeDHT():void
+ {
+ writeWord(0xFFC4); // marker
+ writeWord(0x01A2); // length
+
+ writeByte(0); // HTYDCinfo
+ for (var i:int=0; i<16; i++) {
+ writeByte(std_dc_luminance_nrcodes[i+1]);
+ }
+ for (var j:int=0; j<=11; j++) {
+ writeByte(std_dc_luminance_values[j]);
+ }
+
+ writeByte(0x10); // HTYACinfo
+ for (var k:int=0; k<16; k++) {
+ writeByte(std_ac_luminance_nrcodes[k+1]);
+ }
+ for (var l:int=0; l<=161; l++) {
+ writeByte(std_ac_luminance_values[l]);
+ }
+
+ writeByte(1); // HTUDCinfo
+ for (var m:int=0; m<16; m++) {
+ writeByte(std_dc_chrominance_nrcodes[m+1]);
+ }
+ for (var n:int=0; n<=11; n++) {
+ writeByte(std_dc_chrominance_values[n]);
+ }
+
+ writeByte(0x11); // HTUACinfo
+ for (var o:int=0; o<16; o++) {
+ writeByte(std_ac_chrominance_nrcodes[o+1]);
+ }
+ for (var p:int=0; p<=161; p++) {
+ writeByte(std_ac_chrominance_values[p]);
+ }
+ }
+
+ private function writeSOS():void
+ {
+ writeWord(0xFFDA); // marker
+ writeWord(12); // length
+ writeByte(3); // nrofcomponents
+ writeByte(1); // IdY
+ writeByte(0); // HTY
+ writeByte(2); // IdU
+ writeByte(0x11); // HTU
+ writeByte(3); // IdV
+ writeByte(0x11); // HTV
+ writeByte(0); // Ss
+ writeByte(0x3f); // Se
+ writeByte(0); // Bf
+ }
+
+ // Core processing
+
+ private function processDU(CDU:Array, fdtbl:Array, DC:Number, HTDC:Array, HTAC:Array):Number
+ {
+ var EOB:BitString = HTAC[0x00];
+ var M16zeroes:BitString = HTAC[0xF0];
+
+ var DU_DCT:Array = fDCTQuant(CDU, fdtbl);
+ //ZigZag reorder
+ for (var j:int=0;j<64;j++) {
+ DU[ZigZag[j]]=DU_DCT[j];
+ }
+ var Diff:int = DU[0] - DC; DC = DU[0];
+ //Encode DC
+ if (Diff==0) {
+ writeBits(HTDC[0]); // Diff might be 0
+ } else {
+ writeBits(HTDC[category[32767+Diff]]);
+ writeBits(bitcode[32767+Diff]);
+ }
+ //Encode ACs
+ var end0pos:int = 63;
+ for (; (end0pos>0)&&(DU[end0pos]==0); end0pos--) {
+ };
+ //end0pos = first element in reverse order !=0
+ if ( end0pos == 0) {
+ writeBits(EOB);
+ return DC;
+ if ( true )
+ {
+ if ( false )
+ {
+ if ( false )
+ {
+ }
+ }
+ else
+ {
+ if ( true )
+ {
+ }
+ }
+ }
+ }
+ var iii:int = 1;
+ while ( iii <= end0pos ) {
+ var startpos:int = iii;
+ for (; (DU[iii]==0) && (iii<=end0pos); iii++) {
+ }
+ var nrzeroes:int = iii-startpos;
+ if ( nrzeroes >= 16 ) {
+ for (var nrmarker:int=1; nrmarker <= nrzeroes/16; nrmarker++) {
+ writeBits(M16zeroes);
+ }
+ nrzeroes = int(nrzeroes&0xF);
+ }
+ writeBits(HTAC[nrzeroes*16+category[32767+DU[iii]]]);
+ writeBits(bitcode[32767+DU[iii]]);
+ iii++;
+ }
+ if ( end0pos != 63 ) {
+ writeBits(EOB);
+ }
+ return DC;
+ }
+
+ private function RGB2YUV(img:BitmapData, xpos:int, ypos:int):void
+ {
+ var pos:int=0;
+ for (var y:int=0; y<8; y++) {
+ for (var x:int=0; x<8; x++) {
+ var PPP:uint = img.getPixel32(xpos+x,ypos+y);
+ var RRR:Number = Number((PPP>>16)&0xFF);
+ var GGG:Number = Number((PPP>> 8)&0xFF);
+ var BBB:Number = Number((PPP )&0xFF);
+ YDU[pos]=((( 0.29900)*RRR+( 0.58700)*GGG+( 0.11400)*BBB))-128;
+ UDU[pos]=(((-0.16874)*RRR+(-0.33126)*GGG+( 0.50000)*BBB));
+ VDU[pos]=((( 0.50000)*RRR+(-0.41869)*GGG+(-0.08131)*BBB));
+ pos++;
+ }
+ }
+ }
+ }
+}
+
+class BitString {
+ public var len:int = 0;
+ public var val:int = 0;
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/RadonDataGrid.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/RadonDataGrid.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/RadonDataGrid.as
new file mode 100644
index 0000000..0f55f47
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/RadonDataGrid.as
@@ -0,0 +1,200 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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.radon.core.controls
+{
+ import flash.display.GradientType;
+ import flash.display.Graphics;
+ import flash.display.InterpolationMethod;
+ import flash.display.Shape;
+ import flash.display.SpreadMethod;
+ import flash.display.Sprite;
+ import flash.geom.Matrix;
+
+ import mx.controls.DataGrid;
+ import mx.controls.dataGridClasses.DataGridColumn;
+ import mx.controls.listClasses.IListItemRenderer;
+ import mx.controls.listClasses.ListBaseContentHolder;
+ import mx.core.FlexShape;
+ import mx.core.mx_internal;
+ import mx.events.DataGridEvent;
+
+ use namespace mx_internal;
+
+ public class RadonDataGrid extends DataGrid
+ {
+ public function RadonDataGrid()
+ {
+ super();
+
+ headerClass = RadonDataGridHeader;
+
+ rowHeight = 34;
+ draggableColumns = false;
+ resizableColumns = false;
+
+ if ( true )
+ {
+ }
+ }
+
+ override protected function drawHighlightIndicator( indicator : Sprite, x : Number, y : Number, width : Number, height : Number,
+ color : uint, itemRenderer : IListItemRenderer ) : void
+ {
+ super.drawSelectionIndicator( indicator, x, y, width, height, color, itemRenderer );
+ var realWidth : Number = unscaledWidth - viewMetrics.left - viewMetrics.right;
+
+ var graphics : Graphics = Sprite( indicator ).graphics;
+ graphics.clear();
+ graphics.beginFill( 0xFFFFFF, 0.15 );
+ graphics.drawRect( 0, 0, realWidth, height );
+ graphics.endFill();
+
+ indicator.x = x;
+ indicator.y = y;
+ }
+
+ override protected function drawSelectionIndicator( indicator : Sprite, x : Number, y : Number, width : Number, height : Number,
+ color : uint, itemRenderer : IListItemRenderer ) : void
+ {
+ super.drawSelectionIndicator( indicator, x, y, width, height, color, itemRenderer );
+ var realWidth : Number = unscaledWidth - viewMetrics.left - viewMetrics.right;
+
+ var type : String = GradientType.LINEAR;
+ var colors : Array = [ 0x2bc9f6, 0x0086ad ];
+ var alphas : Array = [ 1, 1 ];
+ var ratios : Array = [ 0, 190 ];
+ var spreadMethod : String = SpreadMethod.PAD;
+ var interp : String = InterpolationMethod.RGB;
+ var focalPtRatio : Number = 0;
+
+ var matrix : Matrix = new Matrix();
+ var boxRotation : Number = Math.PI / 2; // 90˚
+ var txx : Number = 0;
+ var tyy : Number = 0;
+
+ var graphics : Graphics = Sprite( indicator ).graphics;
+ graphics.clear();
+
+ matrix.createGradientBox( realWidth, height, boxRotation, tx, ty );
+ graphics.beginGradientFill( type, colors, alphas, ratios, matrix, spreadMethod, interp, focalPtRatio );
+
+ //graphics.beginFill(color);
+ graphics.drawRect( 0, 0, realWidth, height );
+ graphics.endFill();
+
+ indicator.x = x;
+ indicator.y = y;
+ }
+
+ override protected function drawRowBackground( s : Sprite, rowIndex : int, y : Number, height : Number, color : uint,
+ dataIndex : int ) : void // NO PMD
+ {
+ var contentHolder : ListBaseContentHolder = ListBaseContentHolder( s.parent );
+
+ var background : Shape;
+
+ if ( rowIndex < s.numChildren )
+ {
+ background = Shape( s.getChildAt( rowIndex ) );
+ }
+ else
+ {
+ background = new FlexShape();
+ background.name = "background";
+ s.addChild( background );
+ }
+
+ background.y = y;
+
+ // Height is usually as tall is the items in the row, but not if
+ // it would extend below the bottom of listContent
+ var height : Number = Math.min( height, contentHolder.height - y );
+
+ var graphics : Graphics = background.graphics;
+ graphics.clear();
+
+ var backgroundAlpha : Number = getStyle( "backgroundAlpha" );
+
+ if ( color == 0x000000 )
+ {
+ backgroundAlpha = 0;
+ }
+ else if ( color == 0xFFFFFF )
+ {
+ backgroundAlpha = 0.04;
+ }
+
+ graphics.beginFill( color, backgroundAlpha );
+ graphics.drawRect( 0, 0, contentHolder.width, height );
+ graphics.endFill();
+ }
+
+ override protected function placeSortArrow() : void
+ {
+ super.placeSortArrow();
+
+ var sortedColumn : DataGridColumn = columns[ sortIndex ];
+
+ for each ( var dgcolumn : Object in columns )
+ {
+ if ( dgcolumn == sortedColumn )
+ {
+ dgcolumn.setStyle( "headerStyleName", "radonDataGridSelectedHeader" );
+ }
+ else
+ {
+ dgcolumn.setStyle( "headerStyleName", "radonDataGridHeader" );
+ }
+
+ switch ( 10 )
+ {
+ case 1:
+ break;
+ case 2:
+ break;
+ case 3:
+ break;
+ case 4:
+ break;
+ default:
+ for ( var i : int = 0; i < 10; i++ )
+ {
+ if ( true && false )
+ {
+ }
+
+ if ( false )
+ return;
+ }
+ break;
+ }
+ }
+ }
+
+ private function get isTrue() : Boolean
+ {
+ return _isTrue;
+ }
+
+ private function set isTrue( value : Boolean ) : void
+ {
+ _isTrue = value;
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/Responder.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/Responder.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/Responder.as
new file mode 100644
index 0000000..4a3bdae
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/Responder.as
@@ -0,0 +1,36 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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
+{
+
+ public class Responder implements IResponder
+ {
+ private var usedInAttribute : Dictionnary = false;
+ private var unusedAttribute : boolean = usedInAttribute;
+
+ public function result( event : Object ) : void
+ {
+ }
+
+
+ public function fault( info : Object ) : void
+ {
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/Simple.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/Simple.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/Simple.as
new file mode 100644
index 0000000..31eba0b
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/Simple.as
@@ -0,0 +1 @@
+package simple { public class Simple { public function Simple ( ) { trace ( "Simple" ); } } }
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/SkinStyles.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/SkinStyles.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/SkinStyles.as
new file mode 100644
index 0000000..9e470c4
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/SkinStyles.as
@@ -0,0 +1,65 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+
+/**
+ * Color of the border.
+ * The following controls support this style: Button, CheckBox,
+ * ComboBox, MenuBar,
+ * NumericStepper, ProgressBar, RadioButton, ScrollBar, Slider, and any
+ * components that support the <code>borderStyle</code> style.
+ * The default value depends on the component class;
+ * if not overriden for the class, the default value is <code>0xB7BABC</code>.
+ */
+[Style(name="borderColor", type="uint", format="Color", inherit="no")]
+
+/**
+ * Radius of component corners.
+ * The following components support this style: Alert, Button, ComboBox,
+ * LinkButton, MenuBar, NumericStepper, Panel, ScrollBar, Tab, TitleWindow,
+ * and any component
+ * that supports a <code>borderStyle</code> property set to <code>"solid"</code>.
+ * The default value depends on the component class;
+ * if not overriden for the class, the default value is <code>0</code>.
+ */
+[Style(name="cornerRadius", type="Number", format="Length", inherit="no")]
+
+/**
+ * Alphas used for the background fill of controls. Use [1, 1] to make the control background
+ * opaque.
+ *
+ * @default [ 0.6, 0.4 ]
+ */
+[Style(name="fillAlphas", type="Array", arrayType="Number", inherit="no")]
+
+/**
+ * Colors used to tint the background of the control.
+ * Pass the same color for both values for a flat-looking control.
+ *
+ * @default [ 0xFFFFFF, 0xCCCCCC ]
+ */
+[Style(name="fillColors", type="Array", arrayType="uint", format="Color", inherit="no")]
+
+/**
+ * Alpha transparencies used for the highlight fill of controls.
+ * The first value specifies the transparency of the top of the highlight and the second value specifies the transparency
+ * of the bottom of the highlight. The highlight covers the top half of the skin.
+ *
+ * @default [ 0.3, 0.0 ]
+ */
+[Style(name="highlightAlphas", type="Array", arrayType="Number", inherit="no")]
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/Sorted.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/Sorted.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/Sorted.as
new file mode 100644
index 0000000..7f62f38
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/Sorted.as
@@ -0,0 +1,62 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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.model
+{
+ import com.model.VO.ConfigVO;
+
+ import de.polygonal.ds.HashMap;
+
+ public class ConfigProxy extends MS2Proxy
+ {
+ public static const NAME:String = "configProxy";
+ internal static const NAME:String = "configProxy";
+ protected static const NAME:String = "configProxy";
+ private static const NAME:String = "configProxy";
+ public const NAME:String = "configProxy";
+ internal const NAME:String = "configProxy";
+ protected const NAME:String = "configProxy";
+ private const NAME:String = "configProxy";
+ public static var NAME:String = "configProxy";
+ internal static var NAME:String = "configProxy";
+ protected static v NAME:String = "configProxy";
+ private static var NAME:String = "configProxy";
+ public var NAME:String = "configProxy";
+ internal var NAME:String = "configProxy";
+ protected var NAME:String = "configProxy";
+ private var NAME:String = "configProxy";
+
+ public static function populateStub():void {
+ }
+ internal static function onInsertConfig(configVO:ConfigVO):void {
+ }
+ protected static function populateStub():void {
+ }
+ private static function populateStub():void {
+ }
+
+ public function populateStub():void {
+ }
+ internal function insertConfig(configVO:CairngormEvent, e : Object):void {
+ }
+ protected function populateStub():void {
+ }
+ private function populateStub( e : Event ):void {
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/Title.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/Title.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/Title.as
new file mode 100644
index 0000000..905bcbc
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/Title.as
@@ -0,0 +1,33 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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 org.viewing
+
+{
+
+ public final class Title
+
+ {
+ [Embed(source="/assets/pass_small.png")]
+ public static const SHOW:String = "true";
+ public static const HIDE:String = "false";
+ private var watcher : ChangeWatcher;
+
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/UnboundMetadata.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/UnboundMetadata.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/UnboundMetadata.as
new file mode 100644
index 0000000..0720854
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/UnboundMetadata.as
@@ -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
+{
+ import flexunit.flexui.controls.FlexUnitLabelsModelLocator;
+
+ import mx.formatters.NumberFormatter;
+ [Event(name="dayChange",type='mx.events.StateChangeEvent')]
+ [Event(name="dayChange",type='DefaultNameEvent')]
+ [Event(name="dayChange2",type="DefaultNmeEvent")]
+ [Event("untypedEvent")]
+ [Event(name="dayChange",type="flash.events.Event")]
+ public class UnboundMetadata
+ {
+ public function get modelLocator() : FlexUnitLabelsModelLocator
+ {
+ return FlexUnitLabelsModelLocator.instance;
+ }
+
+ public function UnboundMetadata()
+ {
+ var lala : int = FlexUnitLabelsModelLocator.instance;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/WorkEvent.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/WorkEvent.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/WorkEvent.as
new file mode 100644
index 0000000..0055143
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/WorkEvent.as
@@ -0,0 +1,205 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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.cairngorm.work
+{
+ import flash.events.Event;
+
+ /**
+ * An event that occurs while processing a work-item.
+ */
+ public class WorkEvent extends Event
+ {
+ //------------------------------------------------------------------------
+ //
+ // Constants
+ //
+ //------------------------------------------------------------------------
+
+ //-------------------------------
+ // Event Types : IWorkItem
+ //-------------------------------
+
+ public static const WORK_START : String = "workStart";
+ public static const WORK_COMPLETE : String = "workComplete";
+ public static const WORK_FAULT : String = "workFault";
+
+ //-------------------------------
+ // Event Types : IWorkFlow
+ //-------------------------------
+
+ public static const WORK_PROGRESS : String = "workProgress";
+ public static const CHILD_START : String = "childStart";
+ public static const CHILD_COMPLETE : String = "childComplete";
+ public static const CHILD_FAULT : String = "childFault";
+
+ //------------------------------------------------------------------------
+ //
+ // Constructor
+ //
+ //------------------------------------------------------------------------
+
+ public function WorkEvent(
+ type : String,
+ workItem : IWorkItem )
+ {
+ super( type );
+ _workItem = workItem;
+ }
+
+ //------------------------------------------------------------------------
+ //
+ // Static Factory Methods
+ //
+ //------------------------------------------------------------------------
+
+ //-------------------------------
+ // Event Types : IWorkItem
+ //-------------------------------
+
+ public static function createStartEvent(
+ workItem : IWorkItem ) : WorkEvent
+ {
+ return new WorkEvent( WORK_START, workItem );
+ }
+
+ public static function createCompleteEvent(
+ workItem : IWorkItem ) : WorkEvent
+ {
+ return new WorkEvent( WORK_COMPLETE, workItem );
+ }
+
+ public static function createFaultEvent(
+ workItem : IWorkItem,
+ message : String = null ) : WorkEvent
+ {
+ var event : WorkEvent = new WorkEvent( WORK_FAULT, workItem );
+ event._message = message;
+ return event;
+ }
+
+ //-------------------------------
+ // Event Types : IWorkFlow
+ //-------------------------------
+
+ public static function createProgressEvent(
+ workItem : IWorkItem,
+ processed : uint,
+ size : uint ) : WorkEvent
+ {
+ var event : WorkEvent = new WorkEvent( WORK_PROGRESS, workItem );
+ event._processed = processed;
+ event._size = size;
+ return event;
+ }
+
+ public static function createChildStartEvent(
+ workItem : IWorkItem ) : WorkEvent
+ {
+ return new WorkEvent( CHILD_START, workItem );
+ }
+
+ public static function createChildCompleteEvent(
+ workItem : IWorkItem ) : WorkEvent
+ {
+ return new WorkEvent( CHILD_COMPLETE, workItem );
+ }
+
+ public static function createChildFaultEvent(
+ workItem : IWorkItem,
+ message : String = null ) : WorkEvent
+ {
+ var event : WorkEvent = new WorkEvent( CHILD_FAULT, workItem );
+ event._message = message;
+ return event;
+ }
+
+ //------------------------------------------------------------------------
+ //
+ // Properties
+ //
+ //------------------------------------------------------------------------
+
+ //-------------------------------
+ // workItem
+ //-------------------------------
+
+ private var _workItem : IWorkItem;
+
+ /**
+ * The work-item that the event applies to.
+ */
+ public function get workItem() : IWorkItem
+ {
+ return _workItem;
+ }
+
+ //-------------------------------
+ // processed
+ //-------------------------------
+
+ private var _processed : uint;
+
+ public function get processed() : uint
+ {
+ return _processed;
+ }
+
+ //-------------------------------
+ // size
+ //-------------------------------
+
+ private var _size : uint;
+
+ public function get size() : uint
+ {
+ return _size;
+ }
+
+ //-------------------------------
+ // message
+ //-------------------------------
+
+ private var _message : String;
+
+ /**
+ * The message desribing the cause of a workFault event.
+ */
+ public function get message() : String
+ {
+ return _message;
+ }
+
+ //------------------------------------------------------------------------
+ //
+ // Overrides : Event
+ //
+ //------------------------------------------------------------------------
+
+ override public function clone() : Event
+ {
+ var event : WorkEvent = new WorkEvent( type, _workItem );
+
+ event._message = _message;
+ event._processed = _processed;
+ event._size = _size;
+
+ return event;
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/asDocs/EmptyClass.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/asDocs/EmptyClass.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/asDocs/EmptyClass.as
new file mode 100644
index 0000000..8d4afd1
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/asDocs/EmptyClass.as
@@ -0,0 +1,38 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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 foo.bar
+{
+ public class MyClass
+ {
+ public var order : int;
+
+ public function foo() : void
+ {
+ }
+
+ protected function foo() : void
+ {
+ }
+
+ public function set foo( value : Boolean) : void
+ {
+ value = value;
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/asDocs/EmptyWithDocClass.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/asDocs/EmptyWithDocClass.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/asDocs/EmptyWithDocClass.as
new file mode 100644
index 0000000..7d2e6d5
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/asDocs/EmptyWithDocClass.as
@@ -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 foo.bar
+{
+ /**
+ * My Class
+ */
+ public class MyClass
+ {
+ /**
+ * order of the class
+ */
+ [Bindable]
+ public var order : int;
+
+ /**
+ * foo
+ */
+ public function foo() : void
+ {
+ }
+
+ /**
+ * foo
+ */
+ protected function foo() : void
+ {
+ }
+
+ public function set foo( value : Boolean) : void
+ {
+ value = value;
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/Duane.mxml
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/Duane.mxml b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/Duane.mxml
new file mode 100644
index 0000000..0adf7a7
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/Duane.mxml
@@ -0,0 +1,154 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+
+ 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.
+
+-->
+<mx:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
+ xmlns:s="library://ns.adobe.com/flex/spark"
+ xmlns:mx="library://ns.adobe.com/flex/halo"
+ applicationComplete="init()"
+ showFlexChrome="false">
+
+
+ <fx:Script>
+ <![CDATA[
+ import flash.events.MouseEvent;
+
+ private var lineWidth:Number = 1;
+ private var lineColor:uint = 0x000000;
+ private var prevX:Number;
+ private var prevY:Number;
+
+ private function init():void
+ {
+ stage.displayState =
+ StageDisplayState.FULL_SCREEN_INTERACTIVE;
+ myCanvas.addEventListener(MouseEvent.MOUSE_MOVE,
+ drawingOn);
+ }
+
+ private function drawingOff():void
+ {
+ myCanvas.removeEventListener(MouseEvent.MOUSE_MOVE,
+ drawingOn);
+ myButton.label = "Drawing On"
+ }
+
+ //This never gets called but it did not throw an error for Flex PMD???
+ private function iDontGetCalled():void
+ {
+ var i:int = 5;
+ }
+
+ private function drawingOn(event:MouseEvent):void
+ {
+ if(!isNaN(prevX))
+ {
+
+ myCanvas.graphics.lineStyle(lineWidth,
+ lineColor);
+ myCanvas.graphics.moveTo(prevX, prevY);
+ myCanvas.graphics.lineTo(event.localX,
+ event.localY);
+
+ //Unnecessary and deeply nested IF - ELSE should have been caught too??
+ if(!isNaN(prevX))
+ {
+ //Do nothing
+ } else {
+ if(!isNaN(prevX))
+ {
+ //Do nothing
+ } else {
+ if(!isNaN(prevX))
+ {
+ //Do nothing
+ } else {
+
+ if(!isNaN(prevX))
+ {
+ //Do
+ nothing
+ } else {
+ //do
+ nothing too
+ }
+ }
+ }
+ }
+ }
+ prevX = event.localX;
+ prevY = event.localY;
+ myButton.label = "Drawing Off";
+ }
+
+ private function clear():void
+ {
+ myCanvas.graphics.clear();
+ }
+
+ private function toggleDrawing():void
+ {
+ if (myButton.label == "Drawing Off")
+ {
+ drawingOff();
+ myButton.label = "Drawing On";
+ } else if (myButton.label == "Drawing On")
+ {
+ init();
+ myButton.label = "Drawing Off";
+ }
+ }
+
+ private function changeColor():void
+ {
+ lineColor = myCP.selectedColor;
+ myLabel.text = String(myCP.value);
+ }
+
+
+
+ private function changeThickness():void
+ {
+ lineWidth = mySlider.value;
+ }
+ ]]>
+ </fx:Script>
+
+ <mx:Canvas id="myCanvas" width="100%" height="100%" fontWeight="bold"
+ backgroundAlpha="0.00001" backgroundColor="0xFF44FF" >
+
+ <mx:TitleWindow alpha="1.0" layout="absolute" close="close()"
+ title="Scribbler Settings" showCloseButton="true" width="200"
+ height="178" cornerRadius="16">
+ <s:Button id="myButton" x="10" y="10" width="95"
+ click="toggleDrawing()"/>
+ <mx:ColorPicker x="148" y="10" id="myCP"
+ change="changeColor()"/>
+ <mx:HSlider x="10" y="57" id="mySlider"
+ change="changeThickness()" minimum="1" maximum="10" snapInterval="1"
+ enabled="true" allowTrackClick="true"/>
+ <mx:Label id="myLabel" x="83" y="111" text="Label" width="87"/>
+
+ <mx:Label x="20" y="111" text="Color:"/>
+ <mx:Label x="26.5" y="76" text="Adjust Line Thickness"/>
+ <s:Button x="10" y="39" label="Clear" width="95" click="clear()"
+ />
+ </mx:TitleWindow>
+ </mx:Canvas>
+
+</mx:WindowedApplication>
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/FlexPMD115.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/FlexPMD115.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/FlexPMD115.as
new file mode 100644
index 0000000..00f7209
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/FlexPMD115.as
@@ -0,0 +1,30 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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 foo.bar {
+ public function baz(): void { }
+ public class A
+ {
+ public static const XYZ:String = XYZ; // meant to be "xyz"
+ public static var a:String = a; // meant to be "a"
+ public static const XYZA:String = "XYZA";
+ public const XYZ:String = XYZ; // meant to be "xyz"
+ public var a:String = a; // meant to be "a"
+ public const XYZA:String = "XYZA";
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/FlexPMD141a.mxml
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/FlexPMD141a.mxml b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/FlexPMD141a.mxml
new file mode 100644
index 0000000..44967c2
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/FlexPMD141a.mxml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+
+ 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.
+
+-->
+<mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml">
+ <mx:Script>
+<!-- /* begin editor confusion -->
+ <![CDATA[
+ /* end editor confusion */
+
+ private var object:List = new List();
+ [Bindable]
+ private var counter:int;
+
+ ]]>
+ </mx:Script>
+</mx:HBox>
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/FlexPMD141b.mxml
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/FlexPMD141b.mxml b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/FlexPMD141b.mxml
new file mode 100644
index 0000000..4b0aa20
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/FlexPMD141b.mxml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+
+ 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.
+
+-->
+<mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml">
+ <mx:Script>
+ <!-- /* begin editor confusion -->
+ <![CDATA[
+ /* end editor confusion */
+
+ import mx.collections.ArrayCollection;
+ import mx.collections.ListCollectionView;
+
+ private var variable:ArrayCollection = new ArrayCollection([0, 1, 2]);
+ private var list:ListCollectionView = new ListCollectionView(variable);
+
+ ]]>
+ </mx:Script>
+</mx:HBox>
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/FlexPMD157.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/FlexPMD157.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/FlexPMD157.as
new file mode 100644
index 0000000..210271b
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/FlexPMD157.as
@@ -0,0 +1,33 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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 bug
+{
+ public class FlexPMD157
+ {
+ /**
+ * The name of the home state display.
+ */
+ public static const HOME_STATE:String = "home_state" ;
+
+ /**
+ * The name of the project state display.
+ */
+ public static const PROJECT_STATE:String = "project_state" ;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/FlexPMD173.as
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/FlexPMD173.as b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/FlexPMD173.as
new file mode 100644
index 0000000..293df9a
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/resources/test/bug/FlexPMD173.as
@@ -0,0 +1,40 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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
+{
+ public class PmdPrivateTest
+ {
+ private static const REPORT_SKELETON : XML = read( null );
+ private var REPORT_SKELETON_VAR : XML = readAgain( null );
+
+ private static function read( clazz : Class ) : XML
+ {
+ var byteArray : ByteArray = new clazz() as ByteArray;
+
+ return new XML( byteArray.readUTFBytes( byteArray.length ) ) || REPORT_SKELETON_VAR;
+ }
+
+ private static function readAgain( clazz : Class ) : XML
+ {
+ var byteArray : ByteArray = new clazz() as ByteArray;
+
+ return new XML( byteArray.readUTFBytes( byteArray.length ) );
+ }
+ }
+}
\ No newline at end of file
[23/24] git commit: [flex-utilities]
[refs/heads/feature/pmd-5.2-language-module] - Initial commit of the PMD
language module for Apache Flex
Posted by cd...@apache.org.
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/main/java/org/apache/flex/pmd/parser/impl/AS3Parser.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/parser/parser-impl/src/main/java/org/apache/flex/pmd/parser/impl/AS3Parser.java b/FlexPMD/language-module/parser/parser-impl/src/main/java/org/apache/flex/pmd/parser/impl/AS3Parser.java
new file mode 100644
index 0000000..37d36b8
--- /dev/null
+++ b/FlexPMD/language-module/parser/parser-impl/src/main/java/org/apache/flex/pmd/parser/impl/AS3Parser.java
@@ -0,0 +1,2037 @@
+/*
+ * 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 org.apache.flex.pmd.parser.impl;
+
+import net.sourceforge.pmd.lang.Parser;
+import net.sourceforge.pmd.lang.ParserOptions;
+import net.sourceforge.pmd.lang.TokenManager;
+import net.sourceforge.pmd.lang.ast.ParseException;
+import org.apache.flex.pmd.parser.IParserNode;
+import org.apache.flex.pmd.parser.KeyWords;
+import org.apache.flex.pmd.parser.NodeKind;
+import org.apache.flex.pmd.parser.Operators;
+import org.apache.flex.pmd.parser.ast.Token;
+import org.apache.flex.pmd.parser.exceptions.NullTokenException;
+import org.apache.flex.pmd.parser.exceptions.TokenException;
+import org.apache.flex.pmd.parser.exceptions.UnExpectedTokenException;
+import org.apache.flex.pmd.parser.exceptions.UnExpectedTokenException.Position;
+import org.apache.flex.pmd.utils.FileUtils;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author xagnetti
+ */
+public class AS3Parser implements Parser {
+
+ public static final String ASDOC_COMMENT = "/**";
+ public static final String MULTIPLE_LINES_COMMENT = "/*";
+ public static final String NEW_LINE = "\n";
+ public static final String SINGLE_LINE_COMMENT = "//";
+ private static final String VECTOR = "Vector";
+
+ private Node currentAsDoc;
+ private Node currentFunctionNode;
+ private Node currentMultiLineComment;
+ private String fileName;
+ private boolean isInFor;
+ private AS3Scanner scn;
+ private Token tok;
+
+
+ /**
+ *
+ */
+ public AS3Parser(ParserOptions parserOptions) {
+ this.scn = new AS3Scanner();
+ isInFor = false;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see de.bokelberg.flex.parser.IAS3Parser#buildAst(java.lang.String)
+ */
+ public final IParserNode buildAst(final String filePath) throws IOException,
+ TokenException {
+ List<String> lines = FileUtils.readFile(new File(filePath));
+ return parseLines(filePath, lines.toArray(new String[lines.size()]));
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.parser.IAS3Parser#buildAst(java.lang.String,
+ * java.lang.String[])
+ */
+ public final IParserNode buildAst(final String filePath,
+ final String[] scriptBlockLines) throws TokenException {
+ return parseLines(filePath,
+ scriptBlockLines);
+ }
+
+
+ @Override
+ public ParserOptions getParserOptions() {
+ return null;
+ }
+
+ @Override
+ public TokenManager getTokenManager(String fileName, Reader source) {
+ return null;
+ }
+
+ @Override
+ public boolean canParse() {
+ return false;
+ }
+
+ @Override
+ public net.sourceforge.pmd.lang.ast.Node parse(String fileName, Reader source) throws ParseException {
+ return null;
+ }
+
+ @Override
+ public Map<Integer, String> getSuppressMap() {
+ return null;
+ }
+
+
+ /**
+ * @return
+ */
+ /*private*/ AS3Scanner getScn() {
+ return scn;
+ }
+
+ /*private*/ void nextToken() throws TokenException {
+ nextToken(false);
+ }
+
+ /**
+ * Get the next token Skip comments and newlines for now In the end we want
+ * to keep them though.
+ *
+ * @throws TokenException
+ */
+ private void nextToken(final boolean ignoreDocumentation) throws TokenException {
+ do {
+ if (ignoreDocumentation) {
+ nextTokenIgnoringDocumentation();
+ } else {
+ nextTokenAllowNewLine();
+ }
+ }
+ while (tok.getText().equals(NEW_LINE));
+ }
+
+ /**
+ * tok is first content token
+ *
+ * @throws TokenException
+ */
+ /*private*/ Node parseClassContent() throws TokenException {
+ final Node result = Node.create(NodeKind.CONTENT,
+ tok.getLine(),
+ tok.getColumn());
+ final List<Token> modifiers = new ArrayList<Token>();
+ final List<Node> meta = new ArrayList<Node>();
+
+ while (!tokIs(Operators.RIGHT_CURLY_BRACKET)) {
+ if (tokIs(Operators.LEFT_CURLY_BRACKET)) {
+ result.addChild(parseBlock());
+ }
+ if (tokIs(Operators.LEFT_SQUARE_BRACKET)) {
+ meta.add(parseMetaData());
+ } else if (tokIs(KeyWords.VAR)) {
+ parseClassField(result,
+ modifiers,
+ meta);
+ } else if (tokIs(KeyWords.CONST)) {
+ parseClassConstant(result,
+ modifiers,
+ meta);
+ } else if (tokIs(KeyWords.IMPORT)) {
+ result.addChild(parseImport());
+ } else if (tokIs(KeyWords.FUNCTION)) {
+ parseClassFunctions(result,
+ modifiers,
+ meta);
+ } else {
+ tryToParseCommentNode(result,
+ modifiers);
+ }
+ }
+ return result;
+ }
+
+ /**
+ * tok is empty, since nextToken has not been called before
+ *
+ * @throws UnExpectedTokenException
+ */
+ /*private*/ Node parseCompilationUnit() throws TokenException {
+ final Node result = Node.create(NodeKind.COMPILATION_UNIT,
+ -1,
+ -1);
+
+ nextTokenIgnoringDocumentation();
+ if (tokIs(KeyWords.PACKAGE)) {
+ result.addChild(parsePackage());
+ }
+ result.addChild(parsePackageContent());
+ return result;
+ }
+
+ /**
+ * @return
+ * @throws TokenException
+ */
+ private IParserNode parseExpression() throws TokenException {
+ return parseAssignmentExpression();
+ }
+
+ /**
+ * tok is first content token
+ *
+ * @throws TokenException
+ */
+ /*private*/ Node parseInterfaceContent() throws TokenException {
+ final Node result = Node.create(NodeKind.CONTENT,
+ tok.getLine(),
+ tok.getColumn());
+ while (!tokIs(Operators.RIGHT_CURLY_BRACKET)) {
+ if (tokIs(KeyWords.IMPORT)) {
+ result.addChild(parseImport());
+ } else if (tokIs(KeyWords.FUNCTION)) {
+ result.addChild(parseFunctionSignature());
+ } else if (tokIs(KeyWords.INCLUDE)
+ || tokIs(KeyWords.INCLUDE_AS2)) {
+ result.addChild(parseIncludeExpression());
+ } else if (tokIs(Operators.LEFT_SQUARE_BRACKET)) {
+ while (!tokIs(Operators.RIGHT_SQUARE_BRACKET)) {
+ nextToken();
+ }
+ nextToken();
+ } else {
+ tryToParseCommentNode(result,
+ null);
+ }
+ }
+ return result;
+ }
+
+ /**
+ * tok is first token of content
+ *
+ * @throws UnExpectedTokenException
+ */
+ /*private*/ Node parsePackageContent() throws TokenException {
+ final Node result = Node.create(NodeKind.CONTENT,
+ tok.getLine(),
+ tok.getColumn());
+ final List<Token> modifiers = new ArrayList<Token>();
+ final List<Node> meta = new ArrayList<Node>();
+
+ while (!tokIs(Operators.RIGHT_CURLY_BRACKET)
+ && !tokIs(KeyWords.EOF)) {
+ if (tokIs(KeyWords.IMPORT)) {
+ result.addChild(parseImport());
+ } else if (tokIs(KeyWords.USE)) {
+ result.addChild(parseUse());
+ } else if (tokIs(Operators.LEFT_SQUARE_BRACKET)) {
+ meta.add(parseMetaData());
+ } else if (tokIs(KeyWords.CLASS)) {
+ result.addChild(parseClass(meta,
+ modifiers));
+
+ modifiers.clear();
+ meta.clear();
+ } else if (tokIs(KeyWords.INTERFACE)) {
+ result.addChild(parseInterface(meta,
+ modifiers));
+ modifiers.clear();
+ meta.clear();
+ } else if (tokIs(KeyWords.FUNCTION)) {
+ parseClassFunctions(result,
+ modifiers,
+ meta);
+ } else if (tok.getText().startsWith(ASDOC_COMMENT)) {
+ currentAsDoc = Node.create(NodeKind.AS_DOC,
+ tok.getLine(),
+ tok.getColumn(),
+ tok.getText());
+ nextToken();
+ } else if (tok.getText().startsWith(MULTIPLE_LINES_COMMENT)) {
+ currentMultiLineComment = Node.create(NodeKind.MULTI_LINE_COMMENT,
+ tok.getLine(),
+ tok.getColumn(),
+ tok.getText());
+ nextToken();
+ } else {
+ modifiers.add(tok);
+ nextTokenIgnoringDocumentation();
+ }
+ }
+ return result;
+ }
+
+ /**
+ * @return
+ * @throws TokenException
+ */
+ /*private*/ Node parsePrimaryExpression() throws TokenException {
+ Node result = Node.create(NodeKind.PRIMARY,
+ tok.getLine(),
+ tok.getColumn(),
+ tok.getText());
+
+ if (tokIs(Operators.LEFT_SQUARE_BRACKET)) {
+ result.addChild(parseArrayLiteral());
+ } else if (tokIs(Operators.LEFT_CURLY_BRACKET)) {
+ result.addChild(parseObjectLiteral());
+ } else if (tokIs(KeyWords.FUNCTION)) {
+ result.addChild(parseLambdaExpression());
+ } else if (tokIs(KeyWords.NEW)) {
+ result = parseNewExpression();
+ } else if (tokIs(Operators.LEFT_PARENTHESIS)) {
+ result.addChild(parseEncapsulatedExpression());
+ } else {
+ nextToken(true);
+ }
+ return result;
+ }
+
+ /**
+ * tok is the first token of a statement
+ *
+ * @throws TokenException
+ */
+ /*private*/ IParserNode parseStatement() throws TokenException {
+ IParserNode result;
+
+ if (tokIs(KeyWords.FOR)) {
+ result = parseFor();
+ } else if (tokIs(KeyWords.IF)) {
+ result = parseIf();
+ } else if (tokIs(KeyWords.SWITCH)) {
+ result = parseSwitch();
+ } else if (tokIs(KeyWords.DO)) {
+ result = parseDo();
+ } else if (tokIs(KeyWords.WHILE)) {
+ result = parseWhile();
+ } else if (tokIs(KeyWords.TRY)) {
+ result = parseTry();
+ } else if (tokIs(KeyWords.CATCH)) {
+ result = parseCatch();
+ } else if (tokIs(KeyWords.FINALLY)) {
+ result = parseFinally();
+ } else if (tokIs(Operators.LEFT_CURLY_BRACKET)) {
+ result = parseBlock();
+ } else if (tokIs(KeyWords.VAR)) {
+ result = parseVar();
+ } else if (tokIs(KeyWords.CONST)) {
+ result = parseConst();
+ } else if (tokIs(KeyWords.RETURN)) {
+ result = parseReturnStatement();
+ } else if (tokIs(Operators.SEMI_COLUMN)) {
+ result = parseEmptyStatement();
+ } else {
+ result = parseExpressionList();
+ skip(Operators.SEMI_COLUMN);
+ }
+ return result;
+ }
+
+ /**
+ * @return
+ * @throws TokenException
+ */
+ private Node parseUnaryExpression() throws TokenException {
+ Node result;
+ if (tokIs(Operators.INCREMENT)) {
+ nextToken();
+ result = Node.create(NodeKind.PRE_INC,
+ tok.getLine(),
+ tok.getColumn(),
+ parseUnaryExpression());
+ } else if (tokIs(Operators.DECREMENT)) {
+ nextToken();
+ result = Node.create(NodeKind.PRE_DEC,
+ tok.getLine(),
+ tok.getColumn(),
+ parseUnaryExpression());
+ } else if (tokIs(Operators.MINUS)) {
+ nextToken();
+ result = Node.create(NodeKind.MINUS,
+ tok.getLine(),
+ tok.getColumn(),
+ parseUnaryExpression());
+ } else if (tokIs(Operators.PLUS)
+ || tokIs(Operators.PLUS_AS2)) {
+ nextToken();
+ result = Node.create(NodeKind.PLUS,
+ tok.getLine(),
+ tok.getColumn(),
+ parseUnaryExpression());
+ } else {
+ result = parseUnaryExpressionNotPlusMinus();
+ }
+ return result;
+ }
+
+ private IParserNode collectVarListContent(final Node result) throws TokenException {
+ result.addChild(parseNameTypeInit());
+ while (tokIs(Operators.COMMA)) {
+ nextToken(true);
+ result.addChild(parseNameTypeInit());
+ }
+ return result;
+ }
+
+ private void consume(final KeyWords keyword) throws TokenException {
+ consume(keyword.toString());
+ }
+
+ private void consume(final Operators operator) throws TokenException {
+ consume(operator.toString());
+ }
+
+ /**
+ * Compare the current token to the parameter. If it equals, get the next
+ * token. If not, throw a runtime exception.
+ *
+ * @param text
+ * @throws UnExpectedTokenException
+ */
+ private void consume(final String text) throws TokenException {
+ while (tok.getText().startsWith("//")) {
+ nextToken();
+ }
+
+ if (!tokIs(text)) {
+ throw new UnExpectedTokenException(tok.getText(),
+ new Position(tok.getLine(), tok.getColumn()),
+ fileName,
+ text);
+ }
+ nextToken();
+ }
+
+ private Node convertMeta(final List<Node> metadataList) {
+ if (metadataList == null
+ || metadataList.isEmpty()) {
+ return null;
+ }
+
+ final Node result = Node.create(NodeKind.META_LIST,
+ tok.getLine(),
+ tok.getColumn());
+
+ for (final Node metadataNode : metadataList) {
+ result.addChild(metadataNode);
+ }
+ return result;
+ }
+
+ private Node convertModifiers(final List<Token> modifierList) {
+ if (modifierList == null) {
+ return null;
+ }
+
+ final Node result = Node.create(NodeKind.MOD_LIST,
+ tok.getLine(),
+ tok.getColumn());
+
+ for (final Token modifierToken : modifierList) {
+ result.addChild(NodeKind.MODIFIER,
+ tok.getLine(),
+ tok.getColumn(),
+ modifierToken.getText());
+ }
+ return result;
+ }
+
+ private Node[] doParseSignature() throws TokenException {
+ consume(KeyWords.FUNCTION);
+
+ Node type = Node.create(NodeKind.TYPE,
+ tok.getLine(),
+ tok.getColumn(),
+ KeyWords.FUNCTION.toString());
+ if (tokIs(KeyWords.SET)
+ || tokIs(KeyWords.GET)) {
+ type = Node.create(NodeKind.TYPE,
+ tok.getLine(),
+ tok.getColumn(),
+ tok.getText());
+ nextToken(); // set or get
+ }
+ final Node name = Node.create(NodeKind.NAME,
+ tok.getLine(),
+ tok.getColumn(),
+ tok.getText());
+ nextToken(); // name
+ final Node params = parseParameterList();
+ final Node returnType = parseOptionalType();
+ return new Node[]
+ {type,
+ name,
+ params,
+ returnType};
+ }
+
+ private NodeKind findFunctionTypeFromSignature(final Node[] signature) {
+ for (final Node node : signature) {
+ if (node.is(NodeKind.TYPE)) {
+ if (node.getStringValue().equals("set")) {
+ return NodeKind.SET;
+ }
+ if (node.getStringValue().equals("get")) {
+ return NodeKind.GET;
+ }
+ return NodeKind.FUNCTION;
+ }
+ }
+ return NodeKind.FUNCTION;
+ }
+
+ /**
+ * Get the next token Skip comments but keep newlines We need this method for
+ * beeing able to decide if a returnStatement has an expression
+ *
+ * @throws UnExpectedTokenException
+ */
+ private void nextTokenAllowNewLine() throws TokenException {
+ do {
+ tok = scn.nextToken();
+
+ if (tok == null) {
+ throw new NullTokenException(fileName);
+
+ }
+ if (tok.getText() == null) {
+ throw new NullTokenException(fileName);
+ }
+ }
+ while (tok.getText().startsWith(SINGLE_LINE_COMMENT));
+ }
+
+ private void nextTokenIgnoringDocumentation() throws TokenException {
+ do {
+ nextToken();
+ }
+ while (tok.getText().startsWith(MULTIPLE_LINES_COMMENT));
+ }
+
+ private IParserNode parseAdditiveExpression() throws TokenException {
+ final Node result = Node.create(NodeKind.ADD,
+ tok.getLine(),
+ tok.getColumn(),
+ parseMultiplicativeExpression());
+ while (tokIs(Operators.PLUS)
+ || tokIs(Operators.PLUS_AS2) || tokIs(Operators.MINUS)) {
+ result.addChild(Node.create(NodeKind.OP,
+ tok.getLine(),
+ tok.getColumn(),
+ tok.getText()));
+ nextToken(true);
+ result.addChild(parseMultiplicativeExpression());
+ }
+ return result.numChildren() > 1 ? result
+ : result.getChild(0);
+ }
+
+ // ------------------------------------------------------------------------
+ // language specific recursive descent parsing
+ // ------------------------------------------------------------------------
+
+ private IParserNode parseAndExpression() throws TokenException {
+ final Node result = Node.create(NodeKind.AND,
+ tok.getLine(),
+ tok.getColumn(),
+ parseBitwiseOrExpression());
+ while (tokIs(Operators.AND)
+ || tokIs(Operators.AND_AS2)) {
+ result.addChild(Node.create(NodeKind.OP,
+ tok.getLine(),
+ tok.getColumn(),
+ tok.getText()));
+ nextToken(true);
+ result.addChild(parseBitwiseOrExpression());
+ }
+ return result.numChildren() > 1 ? result
+ : result.getChild(0);
+ }
+
+ /**
+ * tok is ( exit tok is first token after )
+ */
+ private Node parseArgumentList() throws TokenException {
+ consume(Operators.LEFT_PARENTHESIS);
+ final Node result = Node.create(NodeKind.ARGUMENTS,
+ tok.getLine(),
+ tok.getColumn());
+ while (!tokIs(Operators.RIGHT_PARENTHESIS)) {
+ result.addChild(parseExpression());
+ skip(Operators.COMMA);
+ }
+ consume(Operators.RIGHT_PARENTHESIS);
+ return result;
+ }
+
+ private Node parseArrayAccessor(final Node node) throws TokenException {
+ final Node result = Node.create(NodeKind.ARRAY_ACCESSOR,
+ tok.getLine(),
+ tok.getColumn());
+ result.addChild(node);
+ while (tokIs(Operators.LEFT_SQUARE_BRACKET)) {
+ nextToken(true);
+ result.addChild(parseExpression());
+ consume(Operators.RIGHT_SQUARE_BRACKET);
+ }
+ return result;
+ }
+
+ /**
+ * tok is [
+ */
+ private IParserNode parseArrayLiteral() throws TokenException {
+ final Node result = Node.create(NodeKind.ARRAY,
+ tok.getLine(),
+ tok.getColumn());
+ consume(Operators.LEFT_SQUARE_BRACKET);
+ while (!tokIs(Operators.RIGHT_SQUARE_BRACKET)) {
+ result.addChild(parseExpression());
+ skip(Operators.COMMA);
+ }
+ consume(Operators.RIGHT_SQUARE_BRACKET);
+ return result;
+ }
+
+ private IParserNode parseAssignmentExpression() throws TokenException {
+ final Node result = Node.create(NodeKind.ASSIGN,
+ tok.getLine(),
+ tok.getColumn(),
+ parseConditionalExpression());
+ while (tokIs(Operators.EQUAL)
+ || tokIs(Operators.PLUS_EQUAL) || tokIs(Operators.MINUS_EQUAL)
+ || tokIs(Operators.TIMES_EQUAL) || tokIs(Operators.DIVIDED_EQUAL)
+ || tokIs(Operators.MODULO_EQUAL) || tokIs(Operators.AND_EQUAL) || tokIs(Operators.OR_EQUAL)
+ || tokIs(Operators.XOR_EQUAL)) {
+ result.addChild(Node.create(NodeKind.OP,
+ tok.getLine(),
+ tok.getColumn(),
+ tok.getText()));
+ nextToken(true);
+ result.addChild(parseExpression());
+ }
+ return result.numChildren() > 1 ? result
+ : result.getChild(0);
+ }
+
+ private IParserNode parseBitwiseAndExpression() throws TokenException {
+ final Node result = Node.create(NodeKind.B_AND,
+ tok.getLine(),
+ tok.getColumn(),
+ parseEqualityExpression());
+ while (tokIs(Operators.B_AND)) {
+ result.addChild(Node.create(NodeKind.OP,
+ tok.getLine(),
+ tok.getColumn(),
+ tok.getText()));
+ nextToken(true);
+ result.addChild(parseEqualityExpression());
+ }
+ return result.numChildren() > 1 ? result
+ : result.getChild(0);
+ }
+
+ private IParserNode parseBitwiseOrExpression() throws TokenException {
+ final Node result = Node.create(NodeKind.B_OR,
+ tok.getLine(),
+ tok.getColumn(),
+ parseBitwiseXorExpression());
+ while (tokIs(Operators.B_OR)) {
+ result.addChild(Node.create(NodeKind.OP,
+ tok.getLine(),
+ tok.getColumn(),
+ tok.getText()));
+ nextToken(true);
+ result.addChild(parseBitwiseXorExpression());
+ }
+ return result.numChildren() > 1 ? result
+ : result.getChild(0);
+ }
+
+ private IParserNode parseBitwiseXorExpression() throws TokenException {
+ final Node result = Node.create(NodeKind.B_XOR,
+ tok.getLine(),
+ tok.getColumn(),
+ parseBitwiseAndExpression());
+ while (tokIs(Operators.B_XOR)) {
+ result.addChild(Node.create(NodeKind.OP,
+ tok.getLine(),
+ tok.getColumn(),
+ tok.getText()));
+ nextToken(true);
+ result.addChild(parseBitwiseAndExpression());
+ }
+ return result.numChildren() > 1 ? result
+ : result.getChild(0);
+ }
+
+ private Node parseBlock() throws TokenException {
+ return parseBlock(Node.create(NodeKind.BLOCK,
+ tok.getLine(),
+ tok.getColumn()));
+ }
+
+ private Node parseBlock(final Node result) throws TokenException {
+ consume(Operators.LEFT_CURLY_BRACKET);
+
+ while (!tokIs(Operators.RIGHT_CURLY_BRACKET)) {
+ if (tok.getText().startsWith(MULTIPLE_LINES_COMMENT)) {
+ currentFunctionNode.addChild(Node.create(NodeKind.MULTI_LINE_COMMENT,
+ tok.getLine(),
+ tok.getColumn(),
+ tok.getText()));
+ nextToken();
+ } else {
+ result.addChild(parseStatement());
+ }
+ }
+ consume(Operators.RIGHT_CURLY_BRACKET);
+ return result;
+ }
+
+ /**
+ * tok is catch
+ *
+ * @throws TokenException
+ */
+ private Node parseCatch() throws TokenException {
+ consume(KeyWords.CATCH);
+ consume(Operators.LEFT_PARENTHESIS);
+ final Node result = Node.create(NodeKind.CATCH,
+ tok.getLine(),
+ tok.getColumn(),
+ Node.create(NodeKind.NAME,
+ tok.getLine(),
+ tok.getColumn(),
+ tok.getText()));
+ nextToken(true); // name
+ if (tokIs(Operators.COLUMN)) {
+ nextToken(true); // :
+ result.addChild(Node.create(NodeKind.TYPE,
+ tok.getLine(),
+ tok.getColumn(),
+ tok.getText()));
+ nextToken(true); // type
+ }
+ consume(Operators.RIGHT_PARENTHESIS);
+ result.addChild(parseBlock());
+ return result;
+ }
+
+ /**
+ * tok is class
+ *
+ * @param meta
+ * @param modifier
+ * @throws TokenException
+ */
+ private Node parseClass(final List<Node> meta,
+ final List<Token> modifier) throws TokenException {
+ consume(KeyWords.CLASS);
+
+ final Node result = Node.create(NodeKind.CLASS,
+ tok.getLine(),
+ tok.getColumn());
+
+ if (currentAsDoc != null) {
+ result.addChild(currentAsDoc);
+ currentAsDoc = null;
+ }
+ if (currentMultiLineComment != null) {
+ result.addChild(currentMultiLineComment);
+ currentMultiLineComment = null;
+ }
+
+ result.addChild(NodeKind.NAME,
+ tok.getLine(),
+ tok.getColumn(),
+ parseQualifiedName(true));
+
+ result.addChild(convertMeta(meta));
+ result.addChild(convertModifiers(modifier));
+
+ // nextToken( true ); // name
+
+ do {
+ if (tokIs(KeyWords.EXTENDS)) {
+ nextToken(true); // extends
+ result.addChild(NodeKind.EXTENDS,
+ tok.getLine(),
+ tok.getColumn(),
+ parseQualifiedName(false));
+ } else if (tokIs(KeyWords.IMPLEMENTS)) {
+ result.addChild(parseImplementsList());
+ }
+ }
+ while (!tokIs(Operators.LEFT_CURLY_BRACKET));
+ consume(Operators.LEFT_CURLY_BRACKET);
+ result.addChild(parseClassContent());
+ consume(Operators.RIGHT_CURLY_BRACKET);
+ return result;
+ }
+
+ private void parseClassConstant(final Node result,
+ final List<Token> modifiers,
+ final List<Node> meta) throws TokenException {
+ result.addChild(parseConstList(meta,
+ modifiers));
+ if (tokIs(Operators.SEMI_COLUMN)) {
+ nextToken();
+ }
+ meta.clear();
+ modifiers.clear();
+ }
+
+ private void parseClassField(final Node result,
+ final List<Token> modifiers,
+ final List<Node> meta) throws TokenException {
+ final Node varList = parseVarList(meta,
+ modifiers);
+ result.addChild(varList);
+ if (currentAsDoc != null) {
+ varList.addChild(currentAsDoc);
+ currentAsDoc = null;
+ }
+ if (currentMultiLineComment != null) {
+ result.addChild(currentMultiLineComment);
+ currentMultiLineComment = null;
+ }
+ if (tokIs(Operators.SEMI_COLUMN)) {
+ nextToken();
+ }
+ meta.clear();
+ modifiers.clear();
+ }
+
+ private void parseClassFunctions(final Node result,
+ final List<Token> modifiers,
+ final List<Node> meta) throws TokenException {
+ result.addChild(parseFunction(meta,
+ modifiers));
+ meta.clear();
+ modifiers.clear();
+ }
+
+ /**
+ * tok is (
+ *
+ * @throws TokenException
+ */
+ private Node parseCondition() throws TokenException {
+ consume(Operators.LEFT_PARENTHESIS);
+ final Node result = Node.create(NodeKind.CONDITION,
+ tok.getLine(),
+ tok.getColumn(),
+ parseExpression());
+ consume(Operators.RIGHT_PARENTHESIS);
+ return result;
+ }
+
+ private IParserNode parseConditionalExpression() throws TokenException {
+ final IParserNode result = parseOrExpression();
+ if (tokIs(Operators.QUESTION_MARK)) {
+ final Node conditional = Node.create(NodeKind.CONDITIONAL,
+ tok.getLine(),
+ tok.getColumn(),
+ result);
+ nextToken(true); // ?
+ conditional.addChild(parseExpression());
+ nextToken(true); // :
+ conditional.addChild(parseExpression());
+
+ return conditional;
+ }
+ return result;
+ }
+
+ private Node parseConst() throws TokenException {
+ Node result;
+ result = parseConstList(null,
+ null);
+ skip(Operators.SEMI_COLUMN);
+ return result;
+ }
+
+ /**
+ * tok is const
+ *
+ * @param modifiers
+ * @param meta
+ * @throws TokenException
+ */
+ private Node parseConstList(final List<Node> meta,
+ final List<Token> modifiers) throws TokenException {
+ consume(KeyWords.CONST);
+ final Node result = Node.create(NodeKind.CONST_LIST,
+ tok.getLine(),
+ tok.getColumn());
+ result.addChild(convertMeta(meta));
+ result.addChild(convertModifiers(modifiers));
+ collectVarListContent(result);
+ return result;
+ }
+
+ private Node parseDecrement(final Node node) throws TokenException {
+ nextToken(true);
+ final Node result = Node.create(NodeKind.POST_DEC,
+ tok.getLine(),
+ tok.getColumn());
+ result.addChild(node);
+ return result;
+ }
+
+ /**
+ * tok is do
+ *
+ * @throws TokenException
+ */
+ private Node parseDo() throws TokenException {
+ consume(KeyWords.DO);
+ final Node result = Node.create(NodeKind.DO,
+ tok.getLine(),
+ tok.getColumn(),
+ parseStatement());
+ consume(KeyWords.WHILE);
+ result.addChild(parseCondition());
+ if (tokIs(Operators.SEMI_COLUMN)) {
+ nextToken(true);
+ }
+ return result;
+ }
+
+ private Node parseDot(final Node node) throws TokenException {
+ nextToken();
+ if (tokIs(Operators.LEFT_PARENTHESIS)) {
+ nextToken();
+ final Node result = Node.create(NodeKind.E4X_FILTER,
+ tok.getLine(),
+ tok.getColumn());
+ result.addChild(node);
+ result.addChild(parseExpression());
+ consume(Operators.RIGHT_PARENTHESIS);
+ return result;
+ } else if (tokIs(Operators.TIMES)) {
+ final Node result = Node.create(NodeKind.E4X_STAR,
+ tok.getLine(),
+ tok.getColumn());
+ result.addChild(node);
+ return result;
+ }
+ final Node result = Node.create(NodeKind.DOT,
+ tok.getLine(),
+ tok.getColumn());
+ result.addChild(node);
+ result.addChild(parseExpression());
+ return result;
+ }
+
+ private Node parseEmptyStatement() throws TokenException {
+ Node result;
+ result = Node.create(NodeKind.STMT_EMPTY,
+ tok.getLine(),
+ tok.getColumn(),
+ Operators.SEMI_COLUMN.toString());
+ nextToken(true);
+ return result;
+ }
+
+ private Node parseEncapsulatedExpression() throws TokenException {
+ consume(Operators.LEFT_PARENTHESIS);
+ final Node result = Node.create(NodeKind.ENCAPSULATED,
+ tok.getLine(),
+ tok.getColumn());
+ result.addChild(parseExpressionList());
+
+ consume(Operators.RIGHT_PARENTHESIS);
+
+ return result;
+ }
+
+ private IParserNode parseEqualityExpression() throws TokenException {
+ final Node result = Node.create(NodeKind.EQUALITY,
+ tok.getLine(),
+ tok.getColumn(),
+ parseRelationalExpression());
+ while (tokIs(Operators.DOUBLE_EQUAL)
+ || tokIs(Operators.DOUBLE_EQUAL_AS2) || tokIs(Operators.STRICTLY_EQUAL)
+ || tokIs(Operators.NON_EQUAL) || tokIs(Operators.NON_EQUAL_AS2_1)
+ || tokIs(Operators.NON_EQUAL_AS2_2) || tokIs(Operators.NON_STRICTLY_EQUAL)) {
+ result.addChild(Node.create(NodeKind.OP,
+ tok.getLine(),
+ tok.getColumn(),
+ tok.getText()));
+ nextToken(true);
+ result.addChild(parseRelationalExpression());
+ }
+ return result.numChildren() > 1 ? result
+ : result.getChild(0);
+ }
+
+ private IParserNode parseExpressionList() throws TokenException {
+ final Node result = Node.create(NodeKind.EXPR_LIST,
+ tok.getLine(),
+ tok.getColumn(),
+ parseAssignmentExpression());
+ while (tokIs(Operators.COMMA)) {
+ nextToken(true);
+ result.addChild(parseAssignmentExpression());
+ }
+ return result.numChildren() > 1 ? result
+ : result.getChild(0);
+ }
+
+ private Node parseFinally() throws TokenException {
+ Node result;
+ nextToken(true);
+ result = Node.create(NodeKind.FINALLY,
+ tok.getLine(),
+ tok.getColumn(),
+ parseBlock());
+ return result;
+ }
+
+ /**
+ * tok is for
+ *
+ * @throws TokenException
+ */
+ private Node parseFor() throws TokenException {
+ consume(KeyWords.FOR);
+
+ if (tokIs(KeyWords.EACH)) {
+ nextToken();
+ return parseForEach();
+ } else {
+ return parseTraditionalFor();
+ }
+ }
+
+ /**
+ * tok is ( for each( var obj : Type in List )
+ *
+ * @throws TokenException
+ */
+ private Node parseForEach() throws TokenException {
+ consume(Operators.LEFT_PARENTHESIS);
+
+ final Node result = Node.create(NodeKind.FOREACH,
+ tok.getLine(),
+ tok.getColumn());
+ if (tokIs(KeyWords.VAR)) {
+ final Node var = Node.create(NodeKind.VAR,
+ tok.getLine(),
+ tok.getColumn());
+ nextToken();
+ var.addChild(parseNameTypeInit());
+ result.addChild(var);
+ } else {
+ result.addChild(NodeKind.NAME,
+ tok.getLine(),
+ tok.getColumn(),
+ tok.getText());
+ // names allowed?
+ nextToken();
+ }
+ nextToken(); // in
+ result.addChild(NodeKind.IN,
+ tok.getLine(),
+ tok.getColumn(),
+ parseExpression());
+ consume(Operators.RIGHT_PARENTHESIS);
+ result.addChild(parseStatement());
+ return result;
+ }
+
+ private Node parseForIn(final Node result) throws TokenException {
+ nextToken();
+ result.addChild(NodeKind.IN,
+ tok.getLine(),
+ tok.getColumn(),
+ parseExpression());
+ result.setId(NodeKind.FORIN);
+ return result;
+ }
+
+ /**
+ * tok is function
+ *
+ * @param modifiers
+ * @param meta
+ * @throws TokenException
+ */
+ private Node parseFunction(final List<Node> meta,
+ final List<Token> modifiers) throws TokenException {
+ final Node[] signature = doParseSignature();
+ final Node result = Node.create(findFunctionTypeFromSignature(signature),
+ tok.getLine(),
+ tok.getColumn(),
+ signature[0].getStringValue());
+
+ if (currentAsDoc != null) {
+ result.addChild(currentAsDoc);
+ currentAsDoc = null;
+ }
+ if (currentMultiLineComment != null) {
+ result.addChild(currentMultiLineComment);
+ currentMultiLineComment = null;
+ }
+ result.addChild(convertMeta(meta));
+ result.addChild(convertModifiers(modifiers));
+ result.addChild(signature[1]);
+ result.addChild(signature[2]);
+ result.addChild(signature[3]);
+ if (tokIs(Operators.SEMI_COLUMN)) {
+ consume(Operators.SEMI_COLUMN);
+ } else {
+ result.addChild(parseFunctionBlock());
+ }
+ currentFunctionNode = null;
+ return result;
+ }
+
+ /**
+ * tok is { exit tok is the first tok after }
+ *
+ * @throws TokenException
+ * @throws TokenException
+ */
+
+ private Node parseFunctionBlock() throws TokenException {
+ final Node block = Node.create(NodeKind.BLOCK,
+ tok.getLine(),
+ tok.getColumn());
+
+ currentFunctionNode = block;
+
+ parseBlock(block);
+
+ return block;
+ }
+
+ private Node parseFunctionCall(final Node node) throws TokenException {
+ final Node result = Node.create(NodeKind.CALL,
+ tok.getLine(),
+ tok.getColumn());
+ result.addChild(node);
+ while (tokIs(Operators.LEFT_PARENTHESIS)) {
+ result.addChild(parseArgumentList());
+ }
+ while (tokIs(Operators.LEFT_SQUARE_BRACKET)) {
+ result.addChild(parseArrayLiteral());
+ }
+
+ return result;
+ }
+
+ /**
+ * tok is function exit tok is the first token after the optional ;
+ *
+ * @throws TokenException
+ */
+ private Node parseFunctionSignature() throws TokenException {
+ final Node[] signature = doParseSignature();
+ skip(Operators.SEMI_COLUMN);
+ final Node result = Node.create(findFunctionTypeFromSignature(signature),
+ tok.getLine(),
+ tok.getColumn(),
+ signature[0].getStringValue());
+ result.addChild(signature[1]);
+ result.addChild(signature[2]);
+ result.addChild(signature[3]);
+ return result;
+ }
+
+ /**
+ * tok is if
+ *
+ * @throws TokenException
+ */
+ private Node parseIf() throws TokenException {
+ consume(KeyWords.IF);
+ final Node result = Node.create(NodeKind.IF,
+ tok.getLine(),
+ tok.getColumn(),
+ parseCondition());
+ result.addChild(parseStatement());
+ if (tokIs(KeyWords.ELSE)) {
+ nextToken(true);
+ result.addChild(parseStatement());
+ }
+ return result;
+ }
+
+ /**
+ * tok is implements implements a,b,c exit tok is the first token after the
+ * list of qualfied names
+ *
+ * @throws TokenException
+ */
+ private Node parseImplementsList() throws TokenException {
+ consume(KeyWords.IMPLEMENTS);
+
+ final Node result = Node.create(NodeKind.IMPLEMENTS_LIST,
+ tok.getLine(),
+ tok.getColumn());
+ result.addChild(NodeKind.IMPLEMENTS,
+ tok.getLine(),
+ tok.getColumn(),
+ parseQualifiedName(true));
+ while (tokIs(Operators.COMMA)) {
+ nextToken(true);
+ result.addChild(NodeKind.IMPLEMENTS,
+ tok.getLine(),
+ tok.getColumn(),
+ parseQualifiedName(false));
+ }
+ return result;
+ }
+
+ /**
+ * tok is import
+ *
+ * @throws TokenException
+ */
+ private Node parseImport() throws TokenException {
+ consume(KeyWords.IMPORT);
+ final Node result = Node.create(NodeKind.IMPORT,
+ tok.getLine(),
+ tok.getColumn(),
+ parseImportName());
+ skip(Operators.SEMI_COLUMN);
+ return result;
+ }
+
+ /**
+ * tok is the first part of a name the last part can be a star exit tok is
+ * the first token, which doesn't belong to the name
+ *
+ * @throws TokenException
+ */
+ private String parseImportName() throws TokenException {
+ final StringBuilder result = new StringBuilder();
+
+ result.append(tok.getText());
+ nextToken();
+ while (tokIs(Operators.DOT)) {
+ result.append(Operators.DOT);
+ nextToken(); // .
+ result.append(tok.getText());
+ nextToken(); // part of name
+ }
+ return result.toString();
+ }
+
+ private IParserNode parseIncludeExpression() throws TokenException {
+ final Node result = Node.create(NodeKind.INCLUDE,
+ tok.getLine(),
+ tok.getColumn());
+ if (tokIs(KeyWords.INCLUDE)) {
+ consume(KeyWords.INCLUDE);
+ } else if (tokIs(KeyWords.INCLUDE_AS2)) {
+ consume(KeyWords.INCLUDE_AS2);
+ }
+ result.addChild(parseExpression());
+ return result;
+ }
+
+ private Node parseIncrement(final Node node) throws TokenException {
+ nextToken(true);
+ final Node result = Node.create(NodeKind.POST_INC,
+ tok.getLine(),
+ tok.getColumn());
+ result.addChild(node);
+ return result;
+ }
+
+ /**
+ * tok is interface
+ *
+ * @param meta
+ * @param modifier
+ * @throws TokenException
+ */
+ private Node parseInterface(final List<Node> meta,
+ final List<Token> modifier) throws TokenException {
+ consume(KeyWords.INTERFACE);
+ final Node result = Node.create(NodeKind.INTERFACE,
+ tok.getLine(),
+ tok.getColumn());
+
+ if (currentAsDoc != null) {
+ result.addChild(currentAsDoc);
+ currentAsDoc = null;
+ }
+ if (currentMultiLineComment != null) {
+ result.addChild(currentMultiLineComment);
+ currentMultiLineComment = null;
+ }
+ result.addChild(NodeKind.NAME,
+ tok.getLine(),
+ tok.getColumn(),
+ parseQualifiedName(true));
+
+ result.addChild(convertMeta(meta));
+ result.addChild(convertModifiers(modifier));
+
+ if (tokIs(KeyWords.EXTENDS)) {
+ nextToken(); // extends
+ result.addChild(NodeKind.EXTENDS,
+ tok.getLine(),
+ tok.getColumn(),
+ parseQualifiedName(false));
+ }
+ while (tokIs(Operators.COMMA)) {
+ nextToken(); // comma
+ result.addChild(NodeKind.EXTENDS,
+ tok.getLine(),
+ tok.getColumn(),
+ parseQualifiedName(false));
+ }
+ consume(Operators.LEFT_CURLY_BRACKET);
+ result.addChild(parseInterfaceContent());
+ consume(Operators.RIGHT_CURLY_BRACKET);
+ return result;
+ }
+
+ /**
+ * tok is function
+ *
+ * @throws TokenException
+ */
+ private Node parseLambdaExpression() throws TokenException {
+ consume(KeyWords.FUNCTION);
+ Node result;
+
+ if (tok.getText().compareTo("(") == 0) {
+ result = Node.create(NodeKind.LAMBDA,
+ tok.getLine(),
+ tok.getColumn());
+ } else {
+ result = Node.create(NodeKind.FUNCTION,
+ tok.getLine(),
+ tok.getColumn(),
+ tok.getText());
+ nextToken(true);
+ }
+ result.addChild(parseParameterList());
+ result.addChild(parseOptionalType());
+ result.addChild(parseBlock());
+ return result;
+ }
+
+ private IParserNode parseLines(final String filePath,
+ final String[] lines) throws TokenException {
+ setFileName(filePath);
+ scn = new AS3Scanner();
+ scn.setLines(lines);
+ return parseCompilationUnit();
+ }
+
+ /**
+ * tok is [ [id] [id ("test")] [id (name="test",type="a.b.c.Event")] exit
+ * token is the first token after ]
+ *
+ * @throws TokenException
+ */
+ private Node parseMetaData() throws TokenException {
+ final StringBuilder buffer = new StringBuilder();
+
+ final int line = tok.getLine();
+ final int column = tok.getColumn();
+
+ consume(Operators.LEFT_SQUARE_BRACKET);
+ while (!tokIs(Operators.RIGHT_SQUARE_BRACKET)) {
+ if (buffer.length() > 0) {
+ buffer.append(' ');
+ }
+ buffer.append(tok.getText());
+ nextToken();
+ }
+ skip(Operators.RIGHT_SQUARE_BRACKET);
+ final Node metaDataNode = Node.create(NodeKind.META,
+ line,
+ column,
+ buffer.toString());
+
+ return metaDataNode;
+ }
+
+ private IParserNode parseMultiplicativeExpression() throws TokenException {
+ final Node result = Node.create(NodeKind.MULTIPLICATION,
+ tok.getLine(),
+ tok.getColumn(),
+ parseUnaryExpression());
+ while (tokIs(Operators.TIMES)
+ || tokIs(Operators.SLASH) || tokIs(Operators.MODULO)) {
+ result.addChild(Node.create(NodeKind.OP,
+ tok.getLine(),
+ tok.getColumn(),
+ tok.getText()));
+ nextToken(true);
+ result.addChild(parseUnaryExpression());
+ }
+ return result.numChildren() > 1 ? result
+ : result.getChild(0);
+ }
+
+ private String parseNamespaceName() throws TokenException {
+ final String name = tok.getText();
+ nextToken(); // simple name for now
+ return name;
+ }
+
+ private Node parseNameTypeInit() throws TokenException {
+ final Node result = Node.create(NodeKind.NAME_TYPE_INIT,
+ tok.getLine(),
+ tok.getColumn());
+ result.addChild(NodeKind.NAME,
+ tok.getLine(),
+ tok.getColumn(),
+ tok.getText());
+ nextToken(true); // name
+ result.addChild(parseOptionalType());
+ result.addChild(parseOptionalInit());
+ return result;
+ }
+
+ private Node parseNewExpression() throws TokenException {
+ consume(KeyWords.NEW);
+
+ final Node result = Node.create(NodeKind.NEW,
+ tok.getLine(),
+ tok.getColumn());
+ result.addChild(parseExpression()); // name
+ if (tokIs(Operators.VECTOR_START)) {
+ result.addChild(Node.create(NodeKind.VECTOR,
+ tok.getLine(),
+ tok.getColumn(),
+ parseVector()));
+ }
+ if (tokIs(Operators.LEFT_PARENTHESIS)) {
+ result.addChild(parseArgumentList());
+ }
+ return result;
+ }
+
+ /**
+ * tok is {
+ */
+ private Node parseObjectLiteral() throws TokenException {
+ final Node result = Node.create(NodeKind.OBJECT,
+ tok.getLine(),
+ tok.getColumn());
+ consume(Operators.LEFT_CURLY_BRACKET);
+ while (!tokIs(Operators.RIGHT_CURLY_BRACKET)) {
+ result.addChild(parseObjectLiteralPropertyDeclaration());
+ skip(Operators.COMMA);
+ }
+ consume(Operators.RIGHT_CURLY_BRACKET);
+ return result;
+ }
+
+ /*
+ * tok is name
+ */
+ private Node parseObjectLiteralPropertyDeclaration() throws TokenException {
+ final Node result = Node.create(NodeKind.PROP,
+ tok.getLine(),
+ tok.getColumn());
+ final Node name = Node.create(NodeKind.NAME,
+ tok.getLine(),
+ tok.getColumn(),
+ tok.getText());
+ result.addChild(name);
+ nextToken(); // name
+ consume(Operators.COLUMN);
+ result.addChild(NodeKind.VALUE,
+ tok.getLine(),
+ tok.getColumn(),
+ parseExpression());
+ return result;
+ }
+
+ /**
+ * if tok is "=" parse the expression otherwise do nothing
+ *
+ * @return
+ */
+ private Node parseOptionalInit() throws TokenException {
+ Node result = null;
+ if (tokIs(Operators.EQUAL)) {
+ nextToken(true);
+ result = Node.create(NodeKind.INIT,
+ tok.getLine(),
+ tok.getColumn(),
+ parseExpression());
+ }
+ return result;
+ }
+
+ /**
+ * if tok is ":" parse the type otherwise do nothing
+ *
+ * @return
+ * @throws TokenException
+ */
+ private Node parseOptionalType() throws TokenException {
+ Node result = Node.create(NodeKind.TYPE,
+ tok.getLine(),
+ tok.getColumn(),
+ "");
+ if (tokIs(Operators.COLUMN)) {
+ nextToken(true);
+ result = parseType();
+ }
+ return result;
+ }
+
+ private IParserNode parseOrExpression() throws TokenException {
+ final Node result = Node.create(NodeKind.OR,
+ tok.getLine(),
+ tok.getColumn(),
+ parseAndExpression());
+ while (tokIs(Operators.LOGICAL_OR)
+ || tokIs(Operators.LOGICAL_OR_AS2)) {
+ result.addChild(Node.create(NodeKind.OP,
+ tok.getLine(),
+ tok.getColumn(),
+ tok.getText()));
+ nextToken(true);
+ result.addChild(parseAndExpression());
+ }
+ return result.numChildren() > 1 ? result
+ : result.getChild(0);
+ }
+
+ /**
+ * tok is package
+ *
+ * @throws UnExpectedTokenException
+ */
+ private Node parsePackage() throws TokenException {
+ consume(KeyWords.PACKAGE);
+
+ final Node result = Node.create(NodeKind.PACKAGE,
+ tok.getLine(),
+ tok.getColumn());
+ final StringBuilder nameBuffer = new StringBuilder();
+
+ while (!tokIs(Operators.LEFT_CURLY_BRACKET)) {
+ nameBuffer.append(tok.getText());
+ nextToken();
+ }
+ result.addChild(NodeKind.NAME,
+ tok.getLine(),
+ tok.getColumn(),
+ nameBuffer.toString());
+ consume(Operators.LEFT_CURLY_BRACKET);
+ result.addChild(parsePackageContent());
+ consume(Operators.RIGHT_CURLY_BRACKET);
+ return result;
+ }
+
+ /**
+ * tok is the name of a parameter or ...
+ */
+ private Node parseParameter() throws TokenException {
+ final Node result = Node.create(NodeKind.PARAMETER,
+ tok.getLine(),
+ tok.getColumn());
+ if (tokIs(Operators.REST_PARAMETERS)) {
+ nextToken(true); // ...
+ final Node rest = Node.create(NodeKind.REST,
+ tok.getLine(),
+ tok.getColumn(),
+ tok.getText());
+ nextToken(true); // rest
+ result.addChild(rest);
+ } else {
+ result.addChild(parseNameTypeInit());
+ }
+ return result;
+ }
+
+ /**
+ * tok is (
+ *
+ * @throws TokenException
+ */
+ private Node parseParameterList() throws TokenException {
+ consume(Operators.LEFT_PARENTHESIS);
+
+ final Node result = Node.create(NodeKind.PARAMETER_LIST,
+ tok.getLine(),
+ tok.getColumn());
+ while (!tokIs(Operators.RIGHT_PARENTHESIS)) {
+ result.addChild(parseParameter());
+ if (tokIs(Operators.COMMA)) {
+ nextToken(true);
+ } else {
+ break;
+ }
+ }
+ consume(Operators.RIGHT_PARENTHESIS);
+ return result;
+ }
+
+ /**
+ * tok is first part of the name exit tok is the first token after the name
+ *
+ * @throws TokenException
+ */
+ private String parseQualifiedName(final boolean skipPackage) throws TokenException {
+ final StringBuilder buffer = new StringBuilder();
+
+ buffer.append(tok.getText());
+ nextToken();
+ while (tokIs(Operators.DOT)
+ || tokIs(Operators.DOUBLE_COLUMN)) {
+ buffer.append(tok.getText());
+ nextToken();
+ buffer.append(tok.getText());
+ nextToken(); // name
+ }
+
+ if (skipPackage) {
+ return buffer.substring(buffer.lastIndexOf(Operators.DOT.toString()) + 1);
+ }
+ return buffer.toString();
+ }
+
+ private IParserNode parseRelationalExpression() throws TokenException {
+ final Node result = Node.create(NodeKind.RELATION,
+ tok.getLine(),
+ tok.getColumn(),
+ parseShiftExpression());
+ while (tokIs(Operators.INFERIOR)
+ || tokIs(Operators.INFERIOR_AS2) || tokIs(Operators.INFERIOR_OR_EQUAL)
+ || tokIs(Operators.INFERIOR_OR_EQUAL_AS2) || tokIs(Operators.SUPERIOR)
+ || tokIs(Operators.SUPERIOR_AS2) || tokIs(Operators.SUPERIOR_OR_EQUAL)
+ || tokIs(Operators.SUPERIOR_OR_EQUAL_AS2) || tokIs(KeyWords.IS) || tokIs(KeyWords.IN)
+ && !isInFor || tokIs(KeyWords.AS) || tokIs(KeyWords.INSTANCE_OF)) {
+ if (!tokIs(KeyWords.AS)) {
+ result.addChild(Node.create(NodeKind.OP,
+ tok.getLine(),
+ tok.getColumn(),
+ tok.getText()));
+ } else {
+ result.addChild(Node.create(NodeKind.AS,
+ tok.getLine(),
+ tok.getColumn(),
+ tok.getText()));
+ }
+ nextToken(true);
+ result.addChild(parseShiftExpression());
+ }
+ return result.numChildren() > 1 ? result
+ : result.getChild(0);
+ }
+
+ private IParserNode parseReturnStatement() throws TokenException {
+ Node result;
+
+ nextTokenAllowNewLine();
+ if (tokIs(NEW_LINE)
+ || tokIs(Operators.SEMI_COLUMN)) {
+ nextToken(true);
+ result = Node.create(NodeKind.RETURN,
+ tok.getLine(),
+ tok.getColumn(),
+ "");
+ } else {
+ result = Node.create(NodeKind.RETURN,
+ tok.getLine(),
+ tok.getColumn(),
+ parseExpression());
+ skip(Operators.SEMI_COLUMN);
+ }
+ return result;
+ }
+
+ private IParserNode parseShiftExpression() throws TokenException {
+ final Node result = Node.create(NodeKind.SHIFT,
+ tok.getLine(),
+ tok.getColumn(),
+ parseAdditiveExpression());
+ while (tokIs(Operators.DOUBLE_SHIFT_LEFT)
+ || tokIs(Operators.TRIPLE_SHIFT_LEFT) || tokIs(Operators.DOUBLE_SHIFT_RIGHT)
+ || tokIs(Operators.TRIPLE_SHIFT_RIGHT)) {
+ result.addChild(Node.create(NodeKind.OP,
+ tok.getLine(),
+ tok.getColumn(),
+ tok.getText()));
+ nextToken(true);
+ result.addChild(parseAdditiveExpression());
+ }
+ return result.numChildren() > 1 ? result
+ : result.getChild(0);
+ }
+
+ /**
+ * tok is switch
+ *
+ * @throws TokenException
+ */
+ private Node parseSwitch() throws TokenException {
+ consume(KeyWords.SWITCH);
+ final Node result = Node.create(NodeKind.SWITCH,
+ tok.getLine(),
+ tok.getColumn(),
+ parseCondition());
+ if (tokIs(Operators.LEFT_CURLY_BRACKET)) {
+ nextToken();
+ result.addChild(parseSwitchCases());
+ consume(Operators.RIGHT_CURLY_BRACKET);
+ }
+ return result;
+ }
+
+ /**
+ * tok is case, default or the first token of the first statement
+ *
+ * @throws TokenException
+ */
+ private Node parseSwitchBlock() throws TokenException {
+ final Node result = Node.create(NodeKind.SWITCH_BLOCK,
+ tok.getLine(),
+ tok.getColumn());
+ while (!tokIs(KeyWords.CASE)
+ && !tokIs(KeyWords.DEFAULT) && !tokIs(Operators.RIGHT_CURLY_BRACKET)) {
+ result.addChild(parseStatement());
+ }
+ return result;
+ }
+
+ /**
+ * tok is { exit tok is }
+ *
+ * @throws TokenException
+ */
+ private Node parseSwitchCases() throws TokenException {
+ final Node result = Node.create(NodeKind.CASES,
+ tok.getLine(),
+ tok.getColumn());
+ for (; ; ) {
+ if (tokIs(Operators.RIGHT_CURLY_BRACKET)) {
+ break;
+ } else if (tokIs(KeyWords.CASE)) {
+ nextToken(true); // case
+ final Node caseNode = Node.create(NodeKind.CASE,
+ tok.getLine(),
+ tok.getColumn(),
+ parseExpression());
+ consume(Operators.COLUMN);
+ caseNode.addChild(parseSwitchBlock());
+ result.addChild(caseNode);
+ } else if (tokIs(KeyWords.DEFAULT)) {
+ nextToken(true); // default
+ consume(Operators.COLUMN);
+ final Node caseNode = Node.create(NodeKind.CASE,
+ tok.getLine(),
+ tok.getColumn(),
+ Node.create(NodeKind.DEFAULT,
+ tok.getLine(),
+ tok.getColumn(),
+ KeyWords.DEFAULT.toString()));
+ caseNode.addChild(parseSwitchBlock());
+ result.addChild(caseNode);
+ }
+ }
+ return result;
+ }
+
+ /**
+ * tok is ( for( var x : int = 0; i < length; i++ ) for( var s : String in
+ * Object )
+ *
+ * @throws TokenException
+ */
+ private Node parseTraditionalFor() throws TokenException {
+ consume(Operators.LEFT_PARENTHESIS);
+
+ final Node result = Node.create(NodeKind.FOR,
+ tok.getLine(),
+ tok.getColumn());
+ if (!tokIs(Operators.SEMI_COLUMN)) {
+ if (tokIs(KeyWords.VAR)) {
+ result.addChild(NodeKind.INIT,
+ tok.getLine(),
+ tok.getColumn(),
+ parseVarList(null,
+ null));
+ } else {
+ isInFor = true;
+ result.addChild(NodeKind.INIT,
+ tok.getLine(),
+ tok.getColumn(),
+ parseExpression());
+ isInFor = false;
+ }
+ if (tokIs(NodeKind.IN.toString())) {
+ return parseForIn(result);
+ }
+ }
+ consume(Operators.SEMI_COLUMN);
+ if (!tokIs(Operators.SEMI_COLUMN)) {
+ result.addChild(NodeKind.COND,
+ tok.getLine(),
+ tok.getColumn(),
+ parseExpression());
+ }
+ consume(Operators.SEMI_COLUMN);
+ if (!tokIs(Operators.RIGHT_PARENTHESIS)) {
+ result.addChild(NodeKind.ITER,
+ tok.getLine(),
+ tok.getColumn(),
+ parseExpressionList());
+ }
+ consume(Operators.RIGHT_PARENTHESIS);
+ result.addChild(parseStatement());
+ return result;
+ }
+
+ private Node parseTry() throws TokenException {
+ Node result;
+ nextToken(true);
+ result = Node.create(NodeKind.TRY,
+ tok.getLine(),
+ tok.getColumn(),
+ parseBlock());
+ return result;
+ }
+
+ private Node parseType() throws TokenException {
+ Node result;
+ if (tok.getText().equals(VECTOR)) {
+ result = parseVector();
+ } else {
+ result = Node.create(NodeKind.TYPE,
+ tok.getLine(),
+ tok.getColumn(),
+ parseQualifiedName(true));
+ // nextToken( true );
+ }
+ return result;
+ }
+
+ private Node parseUnaryExpressionNotPlusMinus() throws TokenException {
+ Node result;
+ if (tokIs(KeyWords.DELETE)) {
+ nextToken(true);
+ result = Node.create(NodeKind.DELETE,
+ tok.getLine(),
+ tok.getColumn(),
+ parseExpression());
+ } else if (tokIs(KeyWords.VOID)) {
+ nextToken(true);
+ result = Node.create(NodeKind.VOID,
+ tok.getLine(),
+ tok.getColumn(),
+ parseExpression());
+ } else if (tokIs(KeyWords.TYPEOF)) {
+ nextToken(true);
+ result = Node.create(NodeKind.TYPEOF,
+ tok.getLine(),
+ tok.getColumn(),
+ parseExpression());
+ } else if (tokIs("!")
+ || tokIs("not")) {
+ nextToken(true);
+ result = Node.create(NodeKind.NOT,
+ tok.getLine(),
+ tok.getColumn(),
+ parseExpression());
+ } else if (tokIs("~")) {
+ nextToken(true);
+ result = Node.create(NodeKind.B_NOT,
+ tok.getLine(),
+ tok.getColumn(),
+ parseExpression());
+ } else {
+ result = parseUnaryPostfixExpression();
+ }
+ return result;
+ }
+
+ private Node parseUnaryPostfixExpression() throws TokenException {
+ Node node = parsePrimaryExpression();
+
+ if (tokIs(Operators.LEFT_SQUARE_BRACKET)) {
+ node = parseArrayAccessor(node);
+ } else if (tokIs(Operators.LEFT_PARENTHESIS)) {
+ node = parseFunctionCall(node);
+ }
+ if (tokIs(Operators.INCREMENT)) {
+ node = parseIncrement(node);
+ } else if (tokIs(Operators.DECREMENT)) {
+ node = parseDecrement(node);
+ } else if (tokIs(Operators.DOT)
+ || tokIs(Operators.DOUBLE_COLUMN)) {
+ node = parseDot(node);
+ }
+ return node;
+ }
+
+ private Node parseUse() throws TokenException {
+ consume(KeyWords.USE);
+ consume(KeyWords.NAMESPACE);
+ final Node result = Node.create(NodeKind.USE,
+ tok.getLine(),
+ tok.getColumn(),
+ parseNamespaceName());
+ skip(Operators.SEMI_COLUMN);
+ return result;
+ }
+
+ private Node parseVar() throws TokenException {
+ Node result;
+ result = parseVarList(null,
+ null);
+ skip(Operators.SEMI_COLUMN);
+ return result;
+ }
+
+ /**
+ * tok is var var x, y : String, z : int = 0;
+ *
+ * @param modifiers
+ * @param meta
+ * @throws TokenException
+ */
+ private Node parseVarList(final List<Node> meta,
+ final List<Token> modifiers) throws TokenException {
+ consume(KeyWords.VAR);
+ final Node result = Node.create(NodeKind.VAR_LIST,
+ tok.getLine(),
+ tok.getColumn());
+ result.addChild(convertMeta(meta));
+ result.addChild(convertModifiers(modifiers));
+ collectVarListContent(result);
+ return result;
+ }
+
+ private Node parseVector() throws TokenException {
+ final Node result = Node.create(NodeKind.VECTOR,
+ tok.getLine(),
+ tok.getColumn(),
+ "");
+ if (tok.getText().compareTo("Vector") == 0) {
+ nextToken();
+ }
+ consume(Operators.VECTOR_START);
+
+ result.addChild(parseType());
+
+ consume(Operators.SUPERIOR);
+
+ return result;
+ }
+
+ /**
+ * tok is while
+ *
+ * @throws TokenException
+ */
+ private Node parseWhile() throws TokenException {
+ consume(KeyWords.WHILE);
+ final Node result = Node.create(NodeKind.WHILE,
+ tok.getLine(),
+ tok.getColumn());
+ result.addChild(parseCondition());
+ result.addChild(parseStatement());
+ return result;
+ }
+
+ private void setFileName(final String fileNameToParse) {
+ fileName = fileNameToParse;
+ }
+
+ private void skip(final Operators operator) throws TokenException {
+ skip(operator.toString());
+ }
+
+ /**
+ * Skip the current token, if it equals to the parameter
+ *
+ * @param text
+ * @throws UnExpectedTokenException
+ */
+ private void skip(final String text) throws TokenException {
+ if (tokIs(text)) {
+ nextToken();
+ }
+ }
+
+ private boolean tokIs(final KeyWords keyword) {
+ return tok.getText().compareTo(keyword.toString()) == 0;
+ }
+
+ private boolean tokIs(final Operators operator) {
+ return tok.getText().compareTo(operator.toString()) == 0;
+ }
+
+ /**
+ * Compare the current token to the parameter
+ *
+ * @param text
+ * @return true, if tok's text property equals the parameter
+ */
+ private boolean tokIs(final String text) {
+ return tok.getText().equals(text);
+ }
+
+ private void tryToParseCommentNode(final Node result,
+ final List<Token> modifiers) throws TokenException {
+ if (tok.getText().startsWith(ASDOC_COMMENT)) {
+ currentAsDoc = Node.create(NodeKind.AS_DOC,
+ tok.getLine(),
+ tok.getColumn(),
+ tok.getText());
+ nextToken();
+ } else if (tok.getText().startsWith(MULTIPLE_LINES_COMMENT)) {
+ result.addChild(Node.create(NodeKind.MULTI_LINE_COMMENT,
+ tok.getLine(),
+ tok.getColumn(),
+ tok.getText()));
+ nextToken();
+ } else {
+ if (modifiers != null) {
+ modifiers.add(tok);
+ }
+ nextTokenIgnoringDocumentation();
+ }
+ }
+}
[08/24] git commit: [flex-utilities]
[refs/heads/feature/pmd-5.2-language-module] - Initial commit of the PMD
language module for Apache Flex
Posted by cd...@apache.org.
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/UselessOverridenFunctionRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/UselessOverridenFunctionRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/UselessOverridenFunctionRuleTest.java
new file mode 100644
index 0000000..726096c
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/UselessOverridenFunctionRuleTest.java
@@ -0,0 +1,37 @@
+/*
+ * 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 org.apache.flex.pmd.rules.maintanability;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class UselessOverridenFunctionRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("GoodComponent.as", new ViolationPosition[]
+ {new ViolationPosition(26)}),
+ new ExpectedViolation("AbstractRowData.as", new ViolationPosition[]
+ {new ViolationPosition(126)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new UselessOverridenFunctionRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/forbiddenttypes/UseDictionaryTypeRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/forbiddenttypes/UseDictionaryTypeRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/forbiddenttypes/UseDictionaryTypeRuleTest.java
new file mode 100644
index 0000000..04e53fc
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/forbiddenttypes/UseDictionaryTypeRuleTest.java
@@ -0,0 +1,36 @@
+/*
+ * 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 org.apache.flex.pmd.rules.maintanability.forbiddenttypes;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+import org.apache.flex.pmd.rules.maintanability.forbiddentypes.UseDictionaryTypeRule;
+
+public class UseDictionaryTypeRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("Responder.as", new ViolationPosition[]
+ {new ViolationPosition(24)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new UseDictionaryTypeRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/forbiddenttypes/UseGenericTypeRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/forbiddenttypes/UseGenericTypeRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/forbiddenttypes/UseGenericTypeRuleTest.java
new file mode 100644
index 0000000..02acc43
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/forbiddenttypes/UseGenericTypeRuleTest.java
@@ -0,0 +1,50 @@
+/*
+ * 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 org.apache.flex.pmd.rules.maintanability.forbiddenttypes;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+import org.apache.flex.pmd.rules.maintanability.forbiddentypes.UseGenericTypeRule;
+
+import java.util.List;
+
+public class UseGenericTypeRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("GenericType.as", new ViolationPosition[]
+ {new ViolationPosition(27),
+ new ViolationPosition(34),
+ new ViolationPosition(23),
+ new ViolationPosition(24),
+ new ViolationPosition(25)})};
+ }
+
+ @Override
+ protected List<String> getIgnoreFiles() {
+ final List<String> files = super.getIgnoreFiles();
+
+ files.add("bug.FlexPMD181.as");
+ return files;
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new UseGenericTypeRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/forbiddenttypes/UseObjectTypeRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/forbiddenttypes/UseObjectTypeRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/forbiddenttypes/UseObjectTypeRuleTest.java
new file mode 100644
index 0000000..a978fbc
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/forbiddenttypes/UseObjectTypeRuleTest.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 org.apache.flex.pmd.rules.maintanability.forbiddenttypes;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+import org.apache.flex.pmd.rules.maintanability.forbiddentypes.UseObjectTypeRule;
+
+public class UseObjectTypeRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("pseudo.look.IEditLook.as", new ViolationPosition[]
+ {new ViolationPosition(22),
+ new ViolationPosition(23)}),
+ new ExpectedViolation("flexpmd114.a.Test.as", new ViolationPosition[]
+ {new ViolationPosition(30)}),
+ new ExpectedViolation("flexpmd114.b.Test.as", new ViolationPosition[]
+ {new ViolationPosition(30)}),
+ new ExpectedViolation("flexpmd114.c.Test.as", new ViolationPosition[]
+ {new ViolationPosition(30)}),
+ new ExpectedViolation("Looping.as", new ViolationPosition[]
+ {new ViolationPosition(51)}),
+ new ExpectedViolation("com.adobe.ac.ncss.ConfigProxy.as", new ViolationPosition[]
+ {new ViolationPosition(30)}),
+ new ExpectedViolation("Sorted.as", new ViolationPosition[]
+ {new ViolationPosition(55)}),
+ new ExpectedViolation("AbstractRowData.as", new ViolationPosition[]
+ {new ViolationPosition(40)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new UseObjectTypeRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/multitouch/AvoidRollMouseEventRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/multitouch/AvoidRollMouseEventRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/multitouch/AvoidRollMouseEventRuleTest.java
new file mode 100644
index 0000000..9032669
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/multitouch/AvoidRollMouseEventRuleTest.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.flex.pmd.rules.multitouch;
+
+import org.apache.flex.pmd.rules.AbstractRegExpBasedRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractRegexpBasedRule;
+
+public class AvoidRollMouseEventRuleTest extends AbstractRegExpBasedRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {};
+ }
+
+ @Override
+ protected String[] getMatchableLines() {
+ return new String[]
+ {"mouseOut=\"onojverojr\"",
+ "addEventListener( MouseEvent.MOUSE_OUT, onMousOut );",
+ "mouseOver",
+ "MOUSE_OVER",
+ "rollOut",
+ "ROLL_OUT",
+ "rollOver",
+ "ROLL_OVER"};
+ }
+
+ @Override
+ protected AbstractRegexpBasedRule getRegexpBasedRule() {
+ return new AvoidRollMouseEventRule();
+ }
+
+ @Override
+ protected String[] getUnmatchableLines() {
+ return new String[]
+ {"addEventListener( CHANGE, handleChange );",
+ "addEventListener(CHANGE,handleChange);",
+ "addEventListener( CHANGE,"};
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/multitouch/AvoidTooltipRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/multitouch/AvoidTooltipRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/multitouch/AvoidTooltipRuleTest.java
new file mode 100644
index 0000000..92efc63
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/multitouch/AvoidTooltipRuleTest.java
@@ -0,0 +1,50 @@
+/*
+ * 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 org.apache.flex.pmd.rules.multitouch;
+
+import org.apache.flex.pmd.rules.AbstractRegExpBasedRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractRegexpBasedRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class AvoidTooltipRuleTest extends AbstractRegExpBasedRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("DeleteButtonRenderer.mxml", new ViolationPosition[]
+ {new ViolationPosition(22)})};
+ }
+
+ @Override
+ protected String[] getMatchableLines() {
+ return new String[]
+ {"<mx:Button id=\"b1\" label=\"Click Me\" toolTip=\"This Button does nothing.\"/>",
+ "myButton.toolTip = \"Click this new button to create another button.\"; "};
+ }
+
+ @Override
+ protected AbstractRegexpBasedRule getRegexpBasedRule() {
+ return new AvoidTooltipRule();
+ }
+
+ @Override
+ protected String[] getUnmatchableLines() {
+ return new String[]
+ {"addEventListener( CHANGE, handleChange );",
+ "addEventListener(CHANGE,handleChange);",
+ "addEventListener( CHANGE,"};
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/mxml/AbstractMoreThanEntryPointInMxmlRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/mxml/AbstractMoreThanEntryPointInMxmlRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/mxml/AbstractMoreThanEntryPointInMxmlRuleTest.java
new file mode 100644
index 0000000..0433392
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/mxml/AbstractMoreThanEntryPointInMxmlRuleTest.java
@@ -0,0 +1,34 @@
+/*
+ * 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 org.apache.flex.pmd.rules.mxml;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public abstract class AbstractMoreThanEntryPointInMxmlRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("com.adobe.ac.ncss.mxml.IterationsList.mxml", iterationsListViolations()),
+ new ExpectedViolation("com.adobe.ac.ncss.mxml.IterationsList2.mxml",
+ iterationsList2Violations())};
+ }
+
+ abstract protected ViolationPosition[] iterationsList2Violations();
+
+ abstract protected ViolationPosition[] iterationsListViolations();
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/mxml/CodeBehindInMxmlRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/mxml/CodeBehindInMxmlRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/mxml/CodeBehindInMxmlRuleTest.java
new file mode 100644
index 0000000..cb0e366
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/mxml/CodeBehindInMxmlRuleTest.java
@@ -0,0 +1,50 @@
+/*
+ * 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 org.apache.flex.pmd.rules.mxml;
+
+import org.apache.flex.pmd.rules.AbstractRegExpBasedRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractRegexpBasedRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class CodeBehindInMxmlRuleTest extends AbstractRegExpBasedRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("Main.mxml", new ViolationPosition[]
+ {new ViolationPosition(44)})};
+ }
+
+ @Override
+ protected String[] getMatchableLines() {
+ return new String[]
+ {"<Script>",
+ "<mx:Script",
+ "<mx:Script source=",
+ "<Script source="};
+ }
+
+ @Override
+ protected AbstractRegexpBasedRule getRegexpBasedRule() {
+ return new CodeBehindInMxmlRule();
+ }
+
+ @Override
+ protected String[] getUnmatchableLines() {
+ return new String[]
+ {"Script"};
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/mxml/MoreThanOneEntryPointInMxmlRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/mxml/MoreThanOneEntryPointInMxmlRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/mxml/MoreThanOneEntryPointInMxmlRuleTest.java
new file mode 100644
index 0000000..cde566b
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/mxml/MoreThanOneEntryPointInMxmlRuleTest.java
@@ -0,0 +1,39 @@
+/*
+ * 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 org.apache.flex.pmd.rules.mxml;
+
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class MoreThanOneEntryPointInMxmlRuleTest extends AbstractMoreThanEntryPointInMxmlRuleTest {
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new MoreThanOneEntryPointInMxmlRule();
+ }
+
+ @Override
+ protected ViolationPosition[] iterationsList2Violations() {
+ return new ViolationPosition[]
+ {};
+ }
+
+ @Override
+ protected ViolationPosition[] iterationsListViolations() {
+ return new ViolationPosition[]
+ {new ViolationPosition(60)};
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/mxml/MoreThanTwoEntryPointsInMxmlRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/mxml/MoreThanTwoEntryPointsInMxmlRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/mxml/MoreThanTwoEntryPointsInMxmlRuleTest.java
new file mode 100644
index 0000000..d734d62
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/mxml/MoreThanTwoEntryPointsInMxmlRuleTest.java
@@ -0,0 +1,39 @@
+/*
+ * 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 org.apache.flex.pmd.rules.mxml;
+
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class MoreThanTwoEntryPointsInMxmlRuleTest extends AbstractMoreThanEntryPointInMxmlRuleTest {
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new MoreThanTwoEntryPointsInMxmlRule();
+ }
+
+ @Override
+ protected ViolationPosition[] iterationsList2Violations() {
+ return new ViolationPosition[]
+ {};
+ }
+
+ @Override
+ protected ViolationPosition[] iterationsListViolations() {
+ return new ViolationPosition[]
+ {new ViolationPosition(60)};
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/mxml/OnlyOneScriptBlockPerMxmlRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/mxml/OnlyOneScriptBlockPerMxmlRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/mxml/OnlyOneScriptBlockPerMxmlRuleTest.java
new file mode 100644
index 0000000..dafb9b9
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/mxml/OnlyOneScriptBlockPerMxmlRuleTest.java
@@ -0,0 +1,37 @@
+/*
+ * 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 org.apache.flex.pmd.rules.mxml;
+
+import org.apache.flex.pmd.rules.AbstractFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class OnlyOneScriptBlockPerMxmlRuleTest extends AbstractFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("Main.mxml", new ViolationPosition[]
+ {new ViolationPosition(1)}),
+ new ExpectedViolation("AbstractRowData.mxml", new ViolationPosition[]
+ {new ViolationPosition(1)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new OnlyOneScriptBlockPerMxmlRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/mxml/StaticMethodInMxmlRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/mxml/StaticMethodInMxmlRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/mxml/StaticMethodInMxmlRuleTest.java
new file mode 100644
index 0000000..f2ae87b
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/mxml/StaticMethodInMxmlRuleTest.java
@@ -0,0 +1,35 @@
+/*
+ * 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 org.apache.flex.pmd.rules.mxml;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class StaticMethodInMxmlRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("com.adobe.ac.ncss.mxml.IterationsList2.mxml", new ViolationPosition[]
+ {new ViolationPosition(34)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new StaticMethodInMxmlRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/mxml/TooLongScriptBlockRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/mxml/TooLongScriptBlockRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/mxml/TooLongScriptBlockRuleTest.java
new file mode 100644
index 0000000..4e2db4a
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/mxml/TooLongScriptBlockRuleTest.java
@@ -0,0 +1,42 @@
+/*
+ * 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 org.apache.flex.pmd.rules.mxml;
+
+import org.apache.flex.pmd.rules.AbstractFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class TooLongScriptBlockRuleTest extends AbstractFlexRuleTest {
+ @Override
+ public AbstractFlexRule getRule() {
+ return new TooLongScriptBlockRule();
+ }
+
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("bug.Duane.mxml", new ViolationPosition[]
+ {new ViolationPosition(28, 128)}),
+ new ExpectedViolation("bug.FlexPMD233b.mxml", new ViolationPosition[]
+ {new ViolationPosition(49, 129)}),
+ new ExpectedViolation("DeleteButtonRenderer.mxml", new ViolationPosition[]
+ {new ViolationPosition(35, 89)}),
+ new ExpectedViolation("com.adobe.ac.ncss.mxml.IterationsList.mxml",
+ new ViolationPosition[]
+ {new ViolationPosition(26, 80)})};
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/mxml/TooManyStatesInMxmlRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/mxml/TooManyStatesInMxmlRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/mxml/TooManyStatesInMxmlRuleTest.java
new file mode 100644
index 0000000..beccae5
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/mxml/TooManyStatesInMxmlRuleTest.java
@@ -0,0 +1,35 @@
+/*
+ * 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 org.apache.flex.pmd.rules.mxml;
+
+import org.apache.flex.pmd.rules.AbstractFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class TooManyStatesInMxmlRuleTest extends AbstractFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("DeleteButtonRenderer.mxml", new ViolationPosition[]
+ {new ViolationPosition(1)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new TooManyStatesInMxmlRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/naming/BooleanAttributeShouldContainIsHasRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/naming/BooleanAttributeShouldContainIsHasRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/naming/BooleanAttributeShouldContainIsHasRuleTest.java
new file mode 100644
index 0000000..69eeb26
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/naming/BooleanAttributeShouldContainIsHasRuleTest.java
@@ -0,0 +1,33 @@
+/*
+ * 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 org.apache.flex.pmd.rules.naming;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+
+public class BooleanAttributeShouldContainIsHasRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new BooleanAttributeShouldContainIsHasRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/naming/CapitalizeConstantsRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/naming/CapitalizeConstantsRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/naming/CapitalizeConstantsRuleTest.java
new file mode 100644
index 0000000..9f0c836
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/naming/CapitalizeConstantsRuleTest.java
@@ -0,0 +1,43 @@
+/*
+ * 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 org.apache.flex.pmd.rules.naming;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class CapitalizeConstantsRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("AbstractRowData.as", new ViolationPosition[]
+ {new ViolationPosition(33),
+ new ViolationPosition(34)}),
+ new ExpectedViolation("bug.FlexPMD233b.mxml", new ViolationPosition[]
+ {new ViolationPosition(52)}),
+ new ExpectedViolation("com.adobe.ac.ncss.ArrayVO.as", new ViolationPosition[]
+ {new ViolationPosition(27),
+ new ViolationPosition(28)}),
+ new ExpectedViolation("GenericType.as", new ViolationPosition[]
+ {new ViolationPosition(24)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new CapitalizeConstantsRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/naming/IncorrectClassCaseTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/naming/IncorrectClassCaseTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/naming/IncorrectClassCaseTest.java
new file mode 100644
index 0000000..392bf49
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/naming/IncorrectClassCaseTest.java
@@ -0,0 +1,35 @@
+/*
+ * 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 org.apache.flex.pmd.rules.naming;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class IncorrectClassCaseTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("com.adobe.ac.foo.as", new ViolationPosition[]
+ {new ViolationPosition(1, 22)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new IncorrectClassCase();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/naming/IncorrectEventHandlerNameRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/naming/IncorrectEventHandlerNameRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/naming/IncorrectEventHandlerNameRuleTest.java
new file mode 100644
index 0000000..76f0521
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/naming/IncorrectEventHandlerNameRuleTest.java
@@ -0,0 +1,44 @@
+/*
+ * 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 org.apache.flex.pmd.rules.naming;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class IncorrectEventHandlerNameRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("bug.Duane.mxml", new ViolationPosition[]
+ {new ViolationPosition(57)}),
+ new ExpectedViolation("com.adobe.ac.ncss.MyCairngormCommand.as", new ViolationPosition[]
+ {new ViolationPosition(23)}),
+ new ExpectedViolation("com.adobe.ac.ncss.NestedSwitch.as", new ViolationPosition[]
+ {new ViolationPosition(23)}),
+ new ExpectedViolation("parsley.InaccessibleMetaData.as", new ViolationPosition[]
+ {new ViolationPosition(42),
+ new ViolationPosition(48)}),
+ new ExpectedViolation("Sorted.as", new ViolationPosition[]
+ {new ViolationPosition(59)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new IncorrectEventHandlerNameRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/naming/InterfaceNamingRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/naming/InterfaceNamingRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/naming/InterfaceNamingRuleTest.java
new file mode 100644
index 0000000..9cc4cf3
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/naming/InterfaceNamingRuleTest.java
@@ -0,0 +1,40 @@
+/*
+ * 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 org.apache.flex.pmd.rules.naming;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class InterfaceNamingRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("Color.as", new ViolationPosition[]
+ {new ViolationPosition(23)}),
+ new ExpectedViolation("src.fw.data.request.ResultListener.as", new ViolationPosition[]
+ {new ViolationPosition(21)}),
+ new ExpectedViolation("org.as3commons.concurrency.thread.Color.as",
+ new ViolationPosition[]
+ {new ViolationPosition(21)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new InterfaceNamingRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/naming/PackageCaseRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/naming/PackageCaseRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/naming/PackageCaseRuleTest.java
new file mode 100644
index 0000000..d00947a
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/naming/PackageCaseRuleTest.java
@@ -0,0 +1,45 @@
+/*
+ * 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 org.apache.flex.pmd.rules.naming;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+import org.testng.annotations.Test;
+
+@Test(enabled = false) //This test requires test-data that was not donated to Apache
+public class PackageCaseRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("cairngorm.FatController.as", new ViolationPosition[]
+ {new ViolationPosition(-1)}),
+ new ExpectedViolation("FTestError10.IpStack1.as", new ViolationPosition[]
+ {new ViolationPosition(-1)}),
+ new ExpectedViolation("FTestError10.IpStack2.as", new ViolationPosition[]
+ {new ViolationPosition(-1)}),
+ new ExpectedViolation("src.epg.StateExit_AS2.as", new ViolationPosition[]
+ {new ViolationPosition(-1)}),
+ new ExpectedViolation("src.fw.data.request.ResultListener.as", new ViolationPosition[]
+ {new ViolationPosition(-1)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new PackageCaseRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/naming/PropertyHiddenByLocalVariableRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/naming/PropertyHiddenByLocalVariableRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/naming/PropertyHiddenByLocalVariableRuleTest.java
new file mode 100644
index 0000000..3bdaab4
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/naming/PropertyHiddenByLocalVariableRuleTest.java
@@ -0,0 +1,35 @@
+/*
+ * 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 org.apache.flex.pmd.rules.naming;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class PropertyHiddenByLocalVariableRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("com.adobe.ac.ncss.VoidConstructor.as", new ViolationPosition[]
+ {new ViolationPosition(28)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new PropertyHiddenByLocalVariableRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/naming/TooLongFunctionNameRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/naming/TooLongFunctionNameRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/naming/TooLongFunctionNameRuleTest.java
new file mode 100644
index 0000000..22a225a
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/naming/TooLongFunctionNameRuleTest.java
@@ -0,0 +1,35 @@
+/*
+ * 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 org.apache.flex.pmd.rules.naming;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class TooLongFunctionNameRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("flexunit.RulesetTest.as", new ViolationPosition[]
+ {new ViolationPosition(41)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new TooLongFunctionNameRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/naming/TooShortVariableRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/naming/TooShortVariableRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/naming/TooShortVariableRuleTest.java
new file mode 100644
index 0000000..2e25c30
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/naming/TooShortVariableRuleTest.java
@@ -0,0 +1,64 @@
+/*
+ * 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 org.apache.flex.pmd.rules.naming;
+
+import org.apache.flex.pmd.rules.AbstractRegExpBasedRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractRegexpBasedRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class TooShortVariableRuleTest extends AbstractRegExpBasedRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("bug.Duane.mxml", new ViolationPosition[]
+ {new ViolationPosition(54)}),
+ new ExpectedViolation("bug.FlexPMD233b.mxml", new ViolationPosition[]
+ {new ViolationPosition(88)}),
+ new ExpectedViolation("flexpmd114.a.Test.as", new ViolationPosition[]
+ {new ViolationPosition(30)}),
+ new ExpectedViolation("flexpmd114.b.Test.as", new ViolationPosition[]
+ {new ViolationPosition(30)}),
+ new ExpectedViolation("flexpmd114.c.Test.as", new ViolationPosition[]
+ {new ViolationPosition(30)}),
+ new ExpectedViolation("PngEncoder.as", new ViolationPosition[]
+ {new ViolationPosition(30)}),
+ new ExpectedViolation("Looping.as", new ViolationPosition[]
+ {new ViolationPosition(51)})};
+ }
+
+ @Override
+ protected String[] getMatchableLines() {
+ return new String[]
+ {" var toto : int = 0;",
+ " var i : int = 0;",
+ "var ii : int = 0;",
+ "var iii : int = 0;",
+ "for ( var i : int = 0; i < 10; i++ ){}"};
+ }
+
+ @Override
+ protected AbstractRegexpBasedRule getRegexpBasedRule() {
+ return new TooShortVariableRule();
+ }
+
+ @Override
+ protected String[] getUnmatchableLines() {
+ return new String[]
+ {"function lala() : Number",
+ "lala();"};
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/naming/VariableNameEndingWithNumericRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/naming/VariableNameEndingWithNumericRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/naming/VariableNameEndingWithNumericRuleTest.java
new file mode 100644
index 0000000..18bd66a
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/naming/VariableNameEndingWithNumericRuleTest.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 org.apache.flex.pmd.rules.naming;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+import org.testng.annotations.Test;
+
+import java.util.List;
+
+@Test(enabled = false) // This test requires test-data that was not donated to Apache
+public class VariableNameEndingWithNumericRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("PngEncoder.as", new ViolationPosition[]
+ {new ViolationPosition(388),
+ new ViolationPosition(424),
+ new ViolationPosition(442)}),
+ new ExpectedViolation("src.epg.StateExit_AS2.as", new ViolationPosition[]
+ {new ViolationPosition(62),
+ new ViolationPosition(63),
+ new ViolationPosition(69),
+ new ViolationPosition(70),
+ new ViolationPosition(71),
+ new ViolationPosition(60)}),
+ new ExpectedViolation("com.adobe.ac.ncss.BigModel.as", new ViolationPosition[]
+ {new ViolationPosition(82),
+ new ViolationPosition(86),
+ new ViolationPosition(90),
+ new ViolationPosition(94),
+ new ViolationPosition(98)}),
+ new ExpectedViolation("cairngorm.LightController.as", new ViolationPosition[]
+ {new ViolationPosition(115),
+ new ViolationPosition(134),
+ new ViolationPosition(153),
+ new ViolationPosition(172),
+ new ViolationPosition(191)}),
+ new ExpectedViolation("com.adobe.ac.ncss.BigImporterModel.as", new ViolationPosition[]
+ {new ViolationPosition(62),
+ new ViolationPosition(62),
+ new ViolationPosition(62),
+ new ViolationPosition(62),
+ new ViolationPosition(62),
+ new ViolationPosition(64)})};
+ }
+
+ @Override
+ protected List<String> getIgnoreFiles() {
+ final List<String> files = super.getIgnoreFiles();
+
+ files.add("bug.FlexPMD181.as");
+ return files;
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new VariableNameEndingWithNumericRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/naming/WronglyNamedVariableRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/naming/WronglyNamedVariableRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/naming/WronglyNamedVariableRuleTest.java
new file mode 100644
index 0000000..808fc38
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/naming/WronglyNamedVariableRuleTest.java
@@ -0,0 +1,67 @@
+/*
+ * 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 org.apache.flex.pmd.rules.naming;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class WronglyNamedVariableRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("PngEncoder.as", new ViolationPosition[]
+ {new ViolationPosition(323),
+ new ViolationPosition(324),
+ new ViolationPosition(325),
+ new ViolationPosition(326),
+ new ViolationPosition(327),
+ new ViolationPosition(328),
+ new ViolationPosition(329),
+ new ViolationPosition(330),
+ new ViolationPosition(333),
+ new ViolationPosition(334),
+ new ViolationPosition(335),
+ new ViolationPosition(336),
+ new ViolationPosition(370),
+ new ViolationPosition(371),
+ new ViolationPosition(372),
+ new ViolationPosition(373),
+ new ViolationPosition(374),
+ new ViolationPosition(375),
+ new ViolationPosition(376),
+ new ViolationPosition(377),
+ new ViolationPosition(380),
+ new ViolationPosition(381),
+ new ViolationPosition(382),
+ new ViolationPosition(383)}),
+ new ExpectedViolation("GenericType.as", new ViolationPosition[]
+ {new ViolationPosition(32),
+ new ViolationPosition(34)}),
+ new ExpectedViolation("com.adobe.ac.ncss.ConfigProxy.as", new ViolationPosition[]
+ {new ViolationPosition(30)}),
+ new ExpectedViolation("bug.FlexPMD141a.mxml", new ViolationPosition[]
+ {new ViolationPosition(26)}),
+ new ExpectedViolation("AbstractRowData.as", new ViolationPosition[]
+ {new ViolationPosition(40)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new WronglyNamedVariableRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/parameterized/ParameterizedRegExpBasedRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/parameterized/ParameterizedRegExpBasedRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/parameterized/ParameterizedRegExpBasedRuleTest.java
new file mode 100644
index 0000000..9ba3f30
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/parameterized/ParameterizedRegExpBasedRuleTest.java
@@ -0,0 +1,39 @@
+/*
+ * 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 org.apache.flex.pmd.rules.parameterized;
+
+import org.apache.flex.pmd.rules.AbstractFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.maintanability.AlertShowRuleTest;
+
+public class ParameterizedRegExpBasedRuleTest extends AbstractFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return AlertShowRuleTest.VIOLATING_FILES;
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ final ParameterizedRegExpBasedRule rule = new ParameterizedRegExpBasedRule();
+
+
+ rule.setProperty(ParameterizedRegExpBasedRule.VIOLATION_SUPPRESS_REGEX_DESCRIPTOR,
+ ".*\\s+Alert.show\\(.*");
+ rule.compilePattern();
+ return rule;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/parameterized/ParameterizedRegExpBasedRuleWithEmptyRegexpTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/parameterized/ParameterizedRegExpBasedRuleWithEmptyRegexpTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/parameterized/ParameterizedRegExpBasedRuleWithEmptyRegexpTest.java
new file mode 100644
index 0000000..15e65a6
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/parameterized/ParameterizedRegExpBasedRuleWithEmptyRegexpTest.java
@@ -0,0 +1,33 @@
+/*
+ * 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 org.apache.flex.pmd.rules.parameterized;
+
+import org.apache.flex.pmd.rules.AbstractFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+
+public class ParameterizedRegExpBasedRuleWithEmptyRegexpTest extends AbstractFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new ParameterizedRegExpBasedRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/parsley/InaccessibleMetaDataRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/parsley/InaccessibleMetaDataRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/parsley/InaccessibleMetaDataRuleTest.java
new file mode 100644
index 0000000..445f201
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/parsley/InaccessibleMetaDataRuleTest.java
@@ -0,0 +1,40 @@
+/*
+ * 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 org.apache.flex.pmd.rules.parsley;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class InaccessibleMetaDataRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("parsley.InaccessibleMetaData.as", new ViolationPosition[]
+ {new ViolationPosition(26, 26),
+ new ViolationPosition(35, 35),
+ new ViolationPosition(47, 47)}),
+ new ExpectedViolation("parsley.InaccessibleMetaDataInternalClass.as",
+ new ViolationPosition[]
+ {new ViolationPosition(21, 21)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new InaccessibleMetaDataRule();
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/parsley/MessageInterceptorSignatureRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/parsley/MessageInterceptorSignatureRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/parsley/MessageInterceptorSignatureRuleTest.java
new file mode 100644
index 0000000..6f7e279
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/parsley/MessageInterceptorSignatureRuleTest.java
@@ -0,0 +1,37 @@
+/*
+ * 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 org.apache.flex.pmd.rules.parsley;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class MessageInterceptorSignatureRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("parsley.MessageInterceptorSignature.as", new ViolationPosition[]
+ {new ViolationPosition(30, 30),
+ new ViolationPosition(35, 35),
+ new ViolationPosition(41, 41)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new MessageInterceptorSignatureRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/parsley/MismatchedManagedEventRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/parsley/MismatchedManagedEventRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/parsley/MismatchedManagedEventRuleTest.java
new file mode 100644
index 0000000..248f637
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/parsley/MismatchedManagedEventRuleTest.java
@@ -0,0 +1,35 @@
+/*
+ * 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 org.apache.flex.pmd.rules.parsley;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class MismatchedManagedEventRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("parsley.MismatchedManagedEvent.as", new ViolationPosition[]
+ {new ViolationPosition(24, 24)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new MismatchedManagedEventRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/parsley/MisplacedMetaDataRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/parsley/MisplacedMetaDataRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/parsley/MisplacedMetaDataRuleTest.java
new file mode 100644
index 0000000..157d031
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/parsley/MisplacedMetaDataRuleTest.java
@@ -0,0 +1,64 @@
+/*
+ * 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 org.apache.flex.pmd.rules.parsley;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class MisplacedMetaDataRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("parsley.MisplacedMetaData.as", new ViolationPosition[]
+ {new ViolationPosition(36, 36),
+ new ViolationPosition(37, 37),
+ new ViolationPosition(38, 38),
+ new ViolationPosition(39, 39),
+ new ViolationPosition(40, 40),
+ new ViolationPosition(41, 41),
+ new ViolationPosition(42, 42),
+ new ViolationPosition(43, 43),
+ new ViolationPosition(46, 46),
+ new ViolationPosition(51, 51),
+ new ViolationPosition(52, 52),
+ new ViolationPosition(53, 53),
+ new ViolationPosition(54, 54),
+ new ViolationPosition(55, 55),
+ new ViolationPosition(56, 56),
+ new ViolationPosition(57, 57),
+ new ViolationPosition(58, 58),
+ new ViolationPosition(21, 21),
+ new ViolationPosition(22, 22),
+ new ViolationPosition(23, 23),
+ new ViolationPosition(24, 24),
+ new ViolationPosition(25, 25),
+ new ViolationPosition(26, 26),
+ new ViolationPosition(27, 27),
+ new ViolationPosition(28, 28),
+ new ViolationPosition(29, 29),
+ new ViolationPosition(30, 30),
+ new ViolationPosition(31, 31),
+ new ViolationPosition(32, 32),
+ new ViolationPosition(33, 33),})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new MisplacedMetaDataRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/parsley/RedundantMessageHandlerTypeAttributeRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/parsley/RedundantMessageHandlerTypeAttributeRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/parsley/RedundantMessageHandlerTypeAttributeRuleTest.java
new file mode 100644
index 0000000..15d0419
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/parsley/RedundantMessageHandlerTypeAttributeRuleTest.java
@@ -0,0 +1,35 @@
+/*
+ * 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 org.apache.flex.pmd.rules.parsley;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class RedundantMessageHandlerTypeAttributeRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("parsley.RedundantMessageHandlerTypeAttribute.as", new ViolationPosition[]
+ {new ViolationPosition(29, 29)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new RedundantMessageHandlerTypeAttributeRule();
+ }
+}
[15/24] git commit: [flex-utilities]
[refs/heads/feature/pmd-5.2-language-module] - Initial commit of the PMD
language module for Apache Flex
Posted by cd...@apache.org.
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/cairngorm/FatControllerRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/cairngorm/FatControllerRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/cairngorm/FatControllerRule.java
new file mode 100644
index 0000000..5468b61
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/cairngorm/FatControllerRule.java
@@ -0,0 +1,88 @@
+/*
+ * 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 org.apache.flex.pmd.rules.cairngorm;
+
+import org.apache.flex.pmd.nodes.IClass;
+import org.apache.flex.pmd.nodes.IPackage;
+import org.apache.flex.pmd.parser.IParserNode;
+import org.apache.flex.pmd.rules.core.AbstractAstFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+import java.util.List;
+
+/**
+ * @author xagnetti
+ */
+public class FatControllerRule extends AbstractAstFlexRule // NO_UCD
+{
+ private static final int DEFAULT_THRESHOLD = 5;
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#isConcernedByTheCurrentFile
+ * ()
+ */
+ @Override
+ public final boolean isConcernedByTheCurrentFile() {
+ return getCurrentFile().getClassName().endsWith("Controller.as");
+ }
+
+ /*
+ * (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 IClass classNode = packageNode.getClassNode();
+
+ if (classNode != null) {
+ final int commandsCount = computeCommandsCountInImport(packageNode.getImports());
+ final int methodsCount = classNode.getFunctions().size();
+
+ if (methodsCount > 0
+ && commandsCount
+ / methodsCount > DEFAULT_THRESHOLD) {
+ addViolation(classNode);
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority()
+ */
+ @Override
+ protected final ViolationPriority getDefaultPriority() {
+ return ViolationPriority.NORMAL;
+ }
+
+ private int computeCommandsCountInImport(final List<IParserNode> imports) {
+ int commandImport = 0;
+
+ if (imports != null) {
+ for (final IParserNode importNode : imports) {
+ if (importNode.getStringValue().endsWith("Command")) {
+ commandImport++;
+ }
+ }
+ }
+ return commandImport;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/cairngorm/ModelLocatorReferencedMoreThanOncePerClassRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/cairngorm/ModelLocatorReferencedMoreThanOncePerClassRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/cairngorm/ModelLocatorReferencedMoreThanOncePerClassRule.java
new file mode 100644
index 0000000..d8aba94
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/cairngorm/ModelLocatorReferencedMoreThanOncePerClassRule.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.flex.pmd.rules.cairngorm;
+
+/**
+ * @author xagnetti
+ */
+public class ModelLocatorReferencedMoreThanOncePerClassRule extends
+ ReferenceModelLocatorOutsideTheMainApplicationRule {
+ private int referencesPerFile;
+
+ /*
+ * (non-Javadoc)
+ * @seecom.adobe.ac.pmd.rules.cairngorm.
+ * ReferenceModelLocatorOutsideTheMainApplicationRule
+ * #isViolationDetectedOnThisMatchingLine(java.lang.String)
+ */
+ @Override
+ protected final boolean isViolationDetectedOnThisMatchingLine(final String line) {
+ if (!line.contains("import")
+ && !line.contains("return")) {
+ referencesPerFile++;
+ }
+ return referencesPerFile > 1;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#onRuleStart()
+ */
+ @Override
+ protected final void onRuleStart() {
+ referencesPerFile = 0;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/cairngorm/ReferenceModelLocatorOutsideTheMainApplicationRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/cairngorm/ReferenceModelLocatorOutsideTheMainApplicationRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/cairngorm/ReferenceModelLocatorOutsideTheMainApplicationRule.java
new file mode 100644
index 0000000..02446fc
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/cairngorm/ReferenceModelLocatorOutsideTheMainApplicationRule.java
@@ -0,0 +1,67 @@
+/*
+ * 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 org.apache.flex.pmd.rules.cairngorm;
+
+import org.apache.flex.pmd.parser.KeyWords;
+import org.apache.flex.pmd.rules.core.AbstractRegexpBasedRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+/**
+ * @author xagnetti
+ */
+public class ReferenceModelLocatorOutsideTheMainApplicationRule extends AbstractRegexpBasedRule // NO_UCD
+{
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractFlexRule#isConcernedByTheCurrentFile()
+ */
+ @Override
+ public final boolean isConcernedByTheCurrentFile() {
+ return !getCurrentFile().getClassName().endsWith("ModelLocator.as")
+ && (!getCurrentFile().isMxml() || !getCurrentFile().isMainApplication());
+ }
+
+ /*
+ * (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.AbstractRegexpBasedRule#getRegexp()
+ */
+ @Override
+ protected final String getRegexp() {
+ return ".*ModelLocator.*";
+ }
+
+ /*
+ * (non-Javadoc)
+ * @seecom.adobe.ac.pmd.rules.core.AbstractRegexpBasedRule#
+ * isViolationDetectedOnThisMatchingLine(java.lang.String)
+ */
+ @Override
+ protected boolean isViolationDetectedOnThisMatchingLine(final String line) {
+ return true; /*!line.contains(KeyWords.IMPORT.toString())
+ && !line.contains(AS3Parser.SINGLE_LINE_COMMENT);*/
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/component/CallLaterDirectlyRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/component/CallLaterDirectlyRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/component/CallLaterDirectlyRule.java
new file mode 100644
index 0000000..505f0df
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/component/CallLaterDirectlyRule.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 org.apache.flex.pmd.rules.component;
+
+import org.apache.flex.pmd.nodes.IFunction;
+import org.apache.flex.pmd.parser.IParserNode;
+import org.apache.flex.pmd.rules.core.AbstractPrimaryAstRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+/**
+ * @author xagnetti
+ */
+public class CallLaterDirectlyRule extends AbstractPrimaryAstRule {
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractPrimaryAstRule#addViolation(com.adobe
+ * .ac.pmd.parser.IParserNode, com.adobe.ac.pmd.nodes.IFunction)
+ */
+ @Override
+ protected void addViolation(final IParserNode statement,
+ final IFunction function) {
+ addViolation(statement);
+ }
+
+ /*
+ * (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.AbstractPrimaryAstRule#getFirstPrimaryToFind()
+ */
+ @Override
+ protected String getFirstPrimaryToFind() {
+ return "callLater";
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/component/UpdateChildrenNumberInUpdateDisplayListRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/component/UpdateChildrenNumberInUpdateDisplayListRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/component/UpdateChildrenNumberInUpdateDisplayListRule.java
new file mode 100644
index 0000000..59781e7
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/component/UpdateChildrenNumberInUpdateDisplayListRule.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 org.apache.flex.pmd.rules.component;
+
+import org.apache.flex.pmd.nodes.IFunction;
+import org.apache.flex.pmd.parser.IParserNode;
+import org.apache.flex.pmd.rules.core.AbstractAstFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+/**
+ * @author xagnetti
+ */
+public class UpdateChildrenNumberInUpdateDisplayListRule extends AbstractAstFlexRule // NO_UCD
+{
+ private static final String[] METHOD_NAMES =
+ {"addChild",
+ "addChildAt",
+ "removeChild",
+ "removeChildAt"};
+ private static final String UPDATE_DISPLAY_LIST = "updateDisplayList";
+
+ /*
+ * (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.getName().equals(UPDATE_DISPLAY_LIST)) {
+ for (final String methodName : METHOD_NAMES) {
+ for (final IParserNode statement : function.findPrimaryStatementsInBody(methodName)) {
+ addViolation(statement);
+ }
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority()
+ */
+ @Override
+ protected final ViolationPriority getDefaultPriority() {
+ return ViolationPriority.HIGH;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/css/StyleBlockInMxmlRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/css/StyleBlockInMxmlRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/css/StyleBlockInMxmlRule.java
new file mode 100644
index 0000000..240e425
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/css/StyleBlockInMxmlRule.java
@@ -0,0 +1,63 @@
+/*
+ * 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 org.apache.flex.pmd.rules.css;
+
+import org.apache.flex.pmd.rules.core.AbstractRegexpBasedRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+/**
+ * @author xagnetti
+ */
+public class StyleBlockInMxmlRule 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.NORMAL;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.rules.core.AbstractRegexpBasedRule#getRegexp()
+ */
+ @Override
+ protected final String getRegexp() {
+ return ".*<mx:Style>.*";
+ }
+
+ /*
+ * (non-Javadoc)
+ * @seecom.adobe.ac.pmd.rules.core.AbstractRegexpBasedRule#
+ * isViolationDetectedOnThisMatchingLine(java.lang.String)
+ */
+ @Override
+ protected final boolean isViolationDetectedOnThisMatchingLine(final String line) {
+ return true;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/css/UseCssInsteadOfEmbedMetaDataRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/css/UseCssInsteadOfEmbedMetaDataRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/css/UseCssInsteadOfEmbedMetaDataRule.java
new file mode 100644
index 0000000..d4de1ad
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/css/UseCssInsteadOfEmbedMetaDataRule.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 org.apache.flex.pmd.rules.css;
+
+import org.apache.flex.pmd.nodes.*;
+import org.apache.flex.pmd.rules.core.AbstractAstFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+import java.util.List;
+
+/**
+ * @author xagnetti
+ */
+public class UseCssInsteadOfEmbedMetaDataRule extends AbstractAstFlexRule {
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#findViolationsFromAttributes
+ * (java.util.List)
+ */
+ @Override
+ protected final void findViolationsFromAttributes(final List<IAttribute> variables) {
+ super.findViolationsFromAttributes(variables);
+
+ findViolationsInMetaDataList(variables);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#findViolationsFromConstants
+ * (java.util.List)
+ */
+ @Override
+ protected final void findViolationsFromConstants(final List<IConstant> constants) {
+ super.findViolationsFromConstants(constants);
+
+ findViolationsInMetaDataList(constants);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority()
+ */
+ @Override
+ protected final ViolationPriority getDefaultPriority() {
+ return ViolationPriority.LOW;
+ }
+
+ private void findViolationsInMetaDataList(final List<? extends IMetaDataListHolder> metaDataList) {
+ for (final IMetaDataListHolder metaData : metaDataList) {
+ final List<IMetaData> embedList = metaData.getMetaData(MetaData.EMBED);
+
+ if (embedList != null) {
+ addViolation(embedList.get(0));
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/empty/AbstractEmptyBlockRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/empty/AbstractEmptyBlockRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/empty/AbstractEmptyBlockRule.java
new file mode 100644
index 0000000..a5def99
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/empty/AbstractEmptyBlockRule.java
@@ -0,0 +1,35 @@
+/*
+ * 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 org.apache.flex.pmd.rules.empty;
+
+import org.apache.flex.pmd.parser.IParserNode;
+import org.apache.flex.pmd.parser.NodeKind;
+import org.apache.flex.pmd.rules.core.AbstractAstFlexRule;
+
+/**
+ * @author xagnetti
+ */
+public abstract class AbstractEmptyBlockRule extends AbstractAstFlexRule {
+ /**
+ * @param block
+ * @return
+ */
+ protected static boolean isBlockEmpty(final IParserNode block) {
+ return block.is(NodeKind.BLOCK)
+ && block.numChildren() == 0 || block.is(NodeKind.STMT_EMPTY);
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/empty/EmptyCatchStatementRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/empty/EmptyCatchStatementRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/empty/EmptyCatchStatementRule.java
new file mode 100644
index 0000000..62691fc
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/empty/EmptyCatchStatementRule.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.flex.pmd.rules.empty;
+
+import org.apache.flex.pmd.parser.IParserNode;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+/**
+ * @author xagnetti
+ */
+public class EmptyCatchStatementRule extends AbstractEmptyBlockRule {
+ /*
+ * (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#visitCatch(com.adobe.ac
+ * .pmd.parser.IParserNode)
+ */
+ @Override
+ protected final void visitCatch(final IParserNode ast) {
+ super.visitCatch(ast);
+
+ if (isBlockEmpty(ast.getChild(2))) {
+ addViolation(ast);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/empty/EmptyIfStmtRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/empty/EmptyIfStmtRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/empty/EmptyIfStmtRule.java
new file mode 100644
index 0000000..732c345
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/empty/EmptyIfStmtRule.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.flex.pmd.rules.empty;
+
+import org.apache.flex.pmd.parser.IParserNode;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+/**
+ * @author xagnetti
+ */
+public class EmptyIfStmtRule extends AbstractEmptyBlockRule {
+ /*
+ * (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#visitIf(com.adobe.ac.pmd
+ * .parser.IParserNode)
+ */
+ @Override
+ protected final void visitIf(final IParserNode ast) {
+ super.visitIf(ast);
+
+ if (isBlockEmpty(ast.getChild(1))) {
+ addViolation(ast);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/event/AbstractEventRelatedRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/event/AbstractEventRelatedRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/event/AbstractEventRelatedRule.java
new file mode 100644
index 0000000..c481474
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/event/AbstractEventRelatedRule.java
@@ -0,0 +1,50 @@
+/*
+ * 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 org.apache.flex.pmd.rules.event;
+
+import org.apache.flex.pmd.nodes.IClass;
+import org.apache.flex.pmd.rules.core.AbstractAstFlexRule;
+
+/**
+ * @author xagnetti
+ */
+public abstract class AbstractEventRelatedRule extends AbstractAstFlexRule {
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#isConcernedByTheCurrentFile
+ * ()
+ */
+ @Override
+ public final boolean isConcernedByTheCurrentFile() {
+ return !getCurrentFile().isMxml();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#findViolations(com.adobe
+ * .ac.pmd.nodes.IClass)
+ */
+ @Override
+ protected void findViolations(final IClass classNode) {
+ if (classNode.getExtensionName() != null
+ && classNode.getExtensionName().endsWith("Event")) {
+ super.findViolations(classNode);
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/event/ConstructorDispatchingEventRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/event/ConstructorDispatchingEventRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/event/ConstructorDispatchingEventRule.java
new file mode 100644
index 0000000..20b5e07
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/event/ConstructorDispatchingEventRule.java
@@ -0,0 +1,60 @@
+/*
+ * 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 org.apache.flex.pmd.rules.event;
+
+import org.apache.flex.pmd.nodes.IFunction;
+import org.apache.flex.pmd.parser.IParserNode;
+import org.apache.flex.pmd.rules.core.AbstractAstFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+/**
+ * @author xagnetti
+ */
+public class ConstructorDispatchingEventRule 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#findViolationsFromConstructor
+ * (com.adobe.ac.pmd.nodes.IFunction)
+ */
+ @Override
+ protected final void findViolationsFromConstructor(final IFunction constructor) {
+ for (final IParserNode statement : constructor.findPrimaryStatementsInBody("dispatchEvent")) {
+ addViolation(statement);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority()
+ */
+ @Override
+ protected final ViolationPriority getDefaultPriority() {
+ return ViolationPriority.HIGH;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/event/DefaultEventNameRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/event/DefaultEventNameRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/event/DefaultEventNameRule.java
new file mode 100644
index 0000000..28e888e
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/event/DefaultEventNameRule.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.flex.pmd.rules.event;
+
+import org.apache.flex.pmd.nodes.IFunction;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+/**
+ * @author xagnetti
+ */
+public class DefaultEventNameRule extends AbstractEventRelatedRule {
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#findViolationsFromConstructor
+ * (com.adobe.ac.pmd.nodes.IFunction)
+ */
+ @Override
+ protected final void findViolationsFromConstructor(final IFunction constructor) {
+ if (constructor.getParameters().size() > 0
+ && constructor.getParameters().get(0).getType().toString().equals("String")
+ && constructor.getParameters().get(0).getInitializationExpression() != null) {
+ addViolation(constructor.getParameters().get(0));
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority()
+ */
+ @Override
+ protected final ViolationPriority getDefaultPriority() {
+ return ViolationPriority.HIGH;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/event/DispatchHardCodedEventNameRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/event/DispatchHardCodedEventNameRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/event/DispatchHardCodedEventNameRule.java
new file mode 100644
index 0000000..b9ece3f
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/event/DispatchHardCodedEventNameRule.java
@@ -0,0 +1,74 @@
+/*
+ * 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 org.apache.flex.pmd.rules.event;
+
+import org.apache.flex.pmd.rules.core.AbstractRegexpBasedRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+/**
+ * @author xagnetti
+ */
+public class DispatchHardCodedEventNameRule extends AbstractRegexpBasedRule {
+ /*
+ * (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.NORMAL;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.rules.core.AbstractRegexpBasedRule#getRegexp()
+ */
+ @Override
+ protected final String getRegexp() {
+ return ".*dispatchEvent *\\( *new Event\\( *(\"|\').*(\"|\') *\\) *\\).*";
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractRegexpBasedRule#isCurrentLineConcerned
+ * (java.lang.String)
+ */
+ @Override
+ protected boolean isCurrentLineConcerned(final String line) {
+ return line.contains("dispatchEvent");
+ }
+
+ /*
+ * (non-Javadoc)
+ * @seecom.adobe.ac.pmd.rules.core.AbstractRegexpBasedRule#
+ * isViolationDetectedOnThisMatchingLine(java.lang.String)
+ */
+ @Override
+ protected final boolean isViolationDetectedOnThisMatchingLine(final String line) {
+ return getMatcher(line).matches();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/event/EventMissingCloneFunctionRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/event/EventMissingCloneFunctionRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/event/EventMissingCloneFunctionRule.java
new file mode 100644
index 0000000..df5ef10
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/event/EventMissingCloneFunctionRule.java
@@ -0,0 +1,74 @@
+/*
+ * 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 org.apache.flex.pmd.rules.event;
+
+import org.apache.flex.pmd.nodes.IClass;
+import org.apache.flex.pmd.nodes.IFunction;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+import java.util.List;
+
+/**
+ * @author xagnetti
+ */
+public class EventMissingCloneFunctionRule extends AbstractEventRelatedRule {
+ private IClass classNode = null;
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.event.AbstractEventRelatedRule#findViolations(com
+ * .adobe.ac.pmd.nodes.IClass)
+ */
+ @Override
+ protected final void findViolations(final IClass classNodeToBeSet) {
+ classNode = classNodeToBeSet;
+ if ("Event".equals(classNode.getExtensionName())) {
+ super.findViolations(classNode);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#findViolations(java.util
+ * .List)
+ */
+ @Override
+ protected final void findViolations(final List<IFunction> functions) {
+ boolean cloneFound = false;
+
+ for (final IFunction functionNode : functions) {
+ if ("clone".equals(functionNode.getName())) {
+ cloneFound = true;
+ break;
+ }
+ }
+ if (!cloneFound) {
+ addViolation(classNode);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority()
+ */
+ @Override
+ protected final ViolationPriority getDefaultPriority() {
+ return ViolationPriority.HIGH;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/event/ListenForHardCodedEventNameRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/event/ListenForHardCodedEventNameRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/event/ListenForHardCodedEventNameRule.java
new file mode 100644
index 0000000..1f241f8
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/event/ListenForHardCodedEventNameRule.java
@@ -0,0 +1,74 @@
+/*
+ * 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 org.apache.flex.pmd.rules.event;
+
+import org.apache.flex.pmd.rules.core.AbstractRegexpBasedRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+/**
+ * @author xagnetti
+ */
+public class ListenForHardCodedEventNameRule extends AbstractRegexpBasedRule {
+ /*
+ * (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.NORMAL;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.rules.core.AbstractRegexpBasedRule#getRegexp()
+ */
+ @Override
+ protected final String getRegexp() {
+ return ".*addEventListener *\\( *(\"|\').*(\"|\').*";
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractRegexpBasedRule#isCurrentLineConcerned
+ * (java.lang.String)
+ */
+ @Override
+ protected boolean isCurrentLineConcerned(final String line) {
+ return line.contains("addEventListener");
+ }
+
+ /*
+ * (non-Javadoc)
+ * @seecom.adobe.ac.pmd.rules.core.AbstractRegexpBasedRule#
+ * isViolationDetectedOnThisMatchingLine(java.lang.String)
+ */
+ @Override
+ protected final boolean isViolationDetectedOnThisMatchingLine(final String line) {
+ return getMatcher(line).matches();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/event/PublicVariableInCustomEventRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/event/PublicVariableInCustomEventRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/event/PublicVariableInCustomEventRule.java
new file mode 100644
index 0000000..e120816
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/event/PublicVariableInCustomEventRule.java
@@ -0,0 +1,52 @@
+/*
+ * 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 org.apache.flex.pmd.rules.event;
+
+import org.apache.flex.pmd.nodes.IAttribute;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+import java.util.List;
+
+/**
+ * @author xagnetti
+ */
+public class PublicVariableInCustomEventRule extends AbstractEventRelatedRule {
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#findViolationsFromAttributes
+ * (java.util.List)
+ */
+ @Override
+ protected final void findViolationsFromAttributes(final List<IAttribute> variables) {
+ for (final IAttribute attribute : variables) {
+ if (attribute.isPublic()) {
+ addViolation(attribute,
+ attribute.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/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/event/UnboundTypeInMetadataRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/event/UnboundTypeInMetadataRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/event/UnboundTypeInMetadataRule.java
new file mode 100644
index 0000000..679ca4f
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/event/UnboundTypeInMetadataRule.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 org.apache.flex.pmd.rules.event;
+
+import org.apache.flex.pmd.files.IFlexFile;
+import org.apache.flex.pmd.nodes.IClass;
+import org.apache.flex.pmd.nodes.IMetaData;
+import org.apache.flex.pmd.nodes.MetaData;
+import org.apache.flex.pmd.rules.core.AbstractAstFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author xagnetti
+ */
+public class UnboundTypeInMetadataRule extends AbstractAstFlexRule {
+ private static final String TYPE = "type";
+
+ /*
+ * (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<IMetaData> eventMetaDatas = classNode.getMetaData(MetaData.EVENT);
+
+ if (eventMetaDatas != null) {
+ findViolationsInMetaDataNode(eventMetaDatas,
+ getFilesInSourcePath());
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority()
+ */
+ @Override
+ protected final ViolationPriority getDefaultPriority() {
+ return ViolationPriority.NORMAL;
+ }
+
+ private void findViolationsInMetaDataNode(final List<IMetaData> eventMetaDatas,
+ final Map<String, IFlexFile> files) {
+ for (final IMetaData metaData : eventMetaDatas) {
+ if (metaData.getProperty(TYPE).length > 0) {
+ final String type = metaData.getProperty(TYPE)[0];
+
+ if (!files.containsKey(type
+ + ".as")
+ && !type.startsWith("mx.") && !type.startsWith("flash.")) {
+ addViolation(metaData,
+ type);
+ }
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/event/UntypedEventMetadataRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/event/UntypedEventMetadataRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/event/UntypedEventMetadataRule.java
new file mode 100644
index 0000000..c7f88e5
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/event/UntypedEventMetadataRule.java
@@ -0,0 +1,64 @@
+/*
+ * 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 org.apache.flex.pmd.rules.event;
+
+import org.apache.flex.pmd.nodes.IClass;
+import org.apache.flex.pmd.nodes.IMetaData;
+import org.apache.flex.pmd.nodes.MetaData;
+import org.apache.flex.pmd.rules.core.AbstractAstFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+import java.util.List;
+
+/**
+ * @author xagnetti
+ */
+public class UntypedEventMetadataRule 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<IMetaData> eventMetaData = classNode.getMetaData(MetaData.EVENT);
+
+ if (eventMetaData != null) {
+ findViolationsInMetaDataNode(eventMetaData);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority()
+ */
+ @Override
+ protected final ViolationPriority getDefaultPriority() {
+ return ViolationPriority.LOW;
+ }
+
+ private void findViolationsInMetaDataNode(final List<IMetaData> eventMetaDatas) {
+ for (final IMetaData metaData : eventMetaDatas) {
+ final String metaDataValue = metaData.getInternalNode().getStringValue();
+
+ if (!metaDataValue.contains("type = ")) {
+ addViolation(metaData);
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/flexunit/EmptyUnitTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/flexunit/EmptyUnitTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/flexunit/EmptyUnitTest.java
new file mode 100644
index 0000000..01535e1
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/flexunit/EmptyUnitTest.java
@@ -0,0 +1,93 @@
+/*
+ * 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 org.apache.flex.pmd.rules.flexunit;
+
+import org.apache.flex.pmd.nodes.IClass;
+import org.apache.flex.pmd.nodes.IFunction;
+import org.apache.flex.pmd.nodes.MetaData;
+import org.apache.flex.pmd.rules.core.AbstractAstFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+/**
+ * @author xagnetti
+ */
+public final class EmptyUnitTest extends AbstractAstFlexRule {
+ private static final String[] ASSERTIONS = new String[]
+ {"assertEquals",
+ "assertObjectEquals",
+ "assertMatch",
+ "assertNoMatch",
+ "assertContained",
+ "assertNotContained",
+ "assertStrictlyEquals",
+ "assertTrue",
+ "assertFalse",
+ "assertNull",
+ "assertNotNull",
+ "assertUndefined",
+ "assertNotUndefined",
+ "assertThat",
+ "handleEvent",
+ "assertEvents",
+ "fail"};
+
+ private boolean isExtendingTestCase;
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#findViolations(com.adobe
+ * .ac.pmd.nodes.IClass)
+ */
+ @Override
+ protected void findViolations(final IClass classNode) {
+ isExtendingTestCase = classNode.getExtensionName() != null
+ && classNode.getExtensionName().endsWith("TestCase");
+
+ super.findViolations(classNode);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#findViolations(com.adobe
+ * .ac.pmd.nodes.IFunction)
+ */
+ @Override
+ protected void findViolations(final IFunction function) {
+ super.findViolations(function);
+
+ if (isExtendingTestCase
+ && function.getName().startsWith("test")
+ && function.findPrimaryStatementInBody(ASSERTIONS).isEmpty()) {
+ addViolation(function);
+ }
+ if (!function.getMetaData(MetaData.TEST).isEmpty()
+ && function.findPrimaryStatementInBody(ASSERTIONS).isEmpty()) {
+ addViolation(function);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority()
+ */
+ @Override
+ protected ViolationPriority getDefaultPriority() {
+ return ViolationPriority.NORMAL;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/AlertShowRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/AlertShowRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/AlertShowRule.java
new file mode 100644
index 0000000..5d836a8
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/AlertShowRule.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 org.apache.flex.pmd.rules.maintanability;
+
+import org.apache.flex.pmd.nodes.IFunction;
+import org.apache.flex.pmd.parser.IParserNode;
+import org.apache.flex.pmd.rules.core.AbstractPrimaryAstRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+/**
+ * @author xagnetti
+ */
+public class AlertShowRule extends AbstractPrimaryAstRule {
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractPrimaryAstRule#addViolation(com.adobe
+ * .ac.pmd.parser.IParserNode, com.adobe.ac.pmd.nodes.IFunction)
+ */
+ @Override
+ protected void addViolation(final IParserNode statement,
+ final IFunction function) {
+ addViolation(statement);
+ }
+
+ /*
+ * (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.AbstractPrimaryAstRule#getFirstPrimaryToFind()
+ */
+ @Override
+ protected String getFirstPrimaryToFind() {
+ return "Alert";
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractPrimaryAstRule#getSecondPrimaryToFind
+ * ()
+ */
+ @Override
+ protected String getSecondPrimaryToFind() {
+ return "show";
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/ArrayFieldWithNoArrayElementTypeRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/ArrayFieldWithNoArrayElementTypeRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/ArrayFieldWithNoArrayElementTypeRule.java
new file mode 100644
index 0000000..4f8b0fa
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/ArrayFieldWithNoArrayElementTypeRule.java
@@ -0,0 +1,85 @@
+/*
+ * 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 org.apache.flex.pmd.rules.maintanability;
+
+import org.apache.flex.pmd.nodes.IAttribute;
+import org.apache.flex.pmd.nodes.IConstant;
+import org.apache.flex.pmd.nodes.IField;
+import org.apache.flex.pmd.nodes.MetaData;
+import org.apache.flex.pmd.rules.core.AbstractAstFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+import java.util.List;
+
+/**
+ * @author xagnetti
+ */
+public class ArrayFieldWithNoArrayElementTypeRule extends AbstractAstFlexRule {
+ private static final String ARRAY_TYPE = "Array";
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#isConcernedByTheCurrentFile
+ * ()
+ */
+ @Override
+ public boolean isConcernedByTheCurrentFile() {
+ return getCurrentFile().isMxml();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#findViolationsFromAttributes
+ * (java.util.List)
+ */
+ @Override
+ protected final void findViolationsFromAttributes(final List<IAttribute> variables) {
+ findViolationFromFieds(variables);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#findViolationsFromConstants
+ * (java.util.List)
+ */
+ @Override
+ protected void findViolationsFromConstants(final List<IConstant> constants) {
+ findViolationFromFieds(constants);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority()
+ */
+ @Override
+ protected final ViolationPriority getDefaultPriority() {
+ return ViolationPriority.NORMAL;
+ }
+
+ private void findViolationFromFieds(final List<? extends IField> fields) {
+ for (final IField variable : fields) {
+ if (ARRAY_TYPE.equals(variable.getType().toString())
+ && variable.getMetaData(MetaData.ARRAY_ELEMENT_TYPE) == null) {
+ addViolation(variable,
+ variable.getName());
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/AvoidProtectedFieldInFinalClassRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/AvoidProtectedFieldInFinalClassRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/AvoidProtectedFieldInFinalClassRule.java
new file mode 100644
index 0000000..a8c7bae
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/AvoidProtectedFieldInFinalClassRule.java
@@ -0,0 +1,81 @@
+/*
+ * 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 org.apache.flex.pmd.rules.maintanability;
+
+import org.apache.flex.pmd.nodes.IAttribute;
+import org.apache.flex.pmd.nodes.IClass;
+import org.apache.flex.pmd.nodes.IFunction;
+import org.apache.flex.pmd.nodes.Modifier;
+import org.apache.flex.pmd.rules.core.AbstractAstFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+import java.util.List;
+
+/**
+ * @author xagnetti
+ */
+public class AvoidProtectedFieldInFinalClassRule 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 boolean isClassFinal = classNode.isFinal();
+
+ findProtectedAttributes(classNode.getAttributes(),
+ isClassFinal);
+ findProtectedMethods(classNode.getFunctions(),
+ isClassFinal);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority()
+ */
+ @Override
+ protected final ViolationPriority getDefaultPriority() {
+ return ViolationPriority.LOW;
+ }
+
+ private void findProtectedAttributes(final List<IAttribute> atributes,
+ final boolean isClassFinal) {
+ if (atributes != null) {
+ for (final IAttribute field : atributes) {
+ if (field.is(Modifier.PROTECTED)
+ && isClassFinal) {
+ addViolation(field,
+ field.getName());
+ }
+ }
+ }
+ }
+
+ private void findProtectedMethods(final List<IFunction> functions,
+ final boolean isClassFinal) {
+ if (functions != null) {
+ for (final IFunction function : functions) {
+ if (function.is(Modifier.PROTECTED)
+ && !function.isOverriden() && isClassFinal) {
+ addViolation(function);
+ }
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/AvoidUseOfAsKeywordRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/AvoidUseOfAsKeywordRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/AvoidUseOfAsKeywordRule.java
new file mode 100644
index 0000000..c76cfea
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/AvoidUseOfAsKeywordRule.java
@@ -0,0 +1,42 @@
+/*
+ * 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 org.apache.flex.pmd.rules.maintanability;
+
+import org.apache.flex.pmd.parser.IParserNode;
+import org.apache.flex.pmd.parser.NodeKind;
+import org.apache.flex.pmd.rules.core.AbstractAstFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+public class AvoidUseOfAsKeywordRule extends AbstractAstFlexRule {
+ @Override
+ protected ViolationPriority getDefaultPriority() {
+ return ViolationPriority.LOW;
+ }
+
+ @Override
+ protected void visitRelationalExpression(final IParserNode ast) {
+ super.visitRelationalExpression(ast);
+
+ if (ast.getChildren() != null) {
+ for (final IParserNode child : ast.getChildren()) {
+ if (child.is(NodeKind.AS)) {
+ addViolation(child);
+ }
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/AvoidUsingPublicStaticFieldRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/AvoidUsingPublicStaticFieldRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/AvoidUsingPublicStaticFieldRule.java
new file mode 100644
index 0000000..64c36eb
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/AvoidUsingPublicStaticFieldRule.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.flex.pmd.rules.maintanability;
+
+import org.apache.flex.pmd.nodes.IAttribute;
+import org.apache.flex.pmd.rules.core.AbstractAstFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+import java.util.List;
+
+/**
+ * @author xagnetti
+ */
+public class AvoidUsingPublicStaticFieldRule extends AbstractAstFlexRule {
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#findViolationsFromAttributes
+ * (java.util.List)
+ */
+ @Override
+ protected void findViolationsFromAttributes(final List<IAttribute> variables) {
+ for (final IAttribute attribute : variables) {
+ if (attribute.isPublic()
+ && attribute.isStatic() && !attribute.getName().contains("instance")) {
+ addViolation(attribute,
+ attribute.getName());
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority()
+ */
+ @Override
+ protected ViolationPriority getDefaultPriority() {
+ return ViolationPriority.HIGH;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/AvoidUsingWithKeyWordRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/AvoidUsingWithKeyWordRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/AvoidUsingWithKeyWordRule.java
new file mode 100644
index 0000000..67efa8e
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/AvoidUsingWithKeyWordRule.java
@@ -0,0 +1,53 @@
+/*
+ * 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 org.apache.flex.pmd.rules.maintanability;
+
+import org.apache.flex.pmd.nodes.IFunction;
+import org.apache.flex.pmd.parser.IParserNode;
+import org.apache.flex.pmd.rules.core.AbstractAstFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+import java.util.List;
+
+/**
+ * @author xagnetti
+ */
+public class AvoidUsingWithKeyWordRule extends AbstractAstFlexRule {
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#findViolations(com.adobe
+ * .ac.pmd.nodes.IFunction)
+ */
+ @Override
+ protected void findViolations(final IFunction function) {
+ final List<IParserNode> withStatements = function.findPrimaryStatementsInBody("with");
+
+ for (final IParserNode withStatement : withStatements) {
+ addViolation(withStatement);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority()
+ */
+ @Override
+ protected ViolationPriority getDefaultPriority() {
+ return ViolationPriority.HIGH;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/ClassAndExtensionAreIdenticalRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/ClassAndExtensionAreIdenticalRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/ClassAndExtensionAreIdenticalRule.java
new file mode 100644
index 0000000..8bcd154
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/ClassAndExtensionAreIdenticalRule.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 org.apache.flex.pmd.rules.maintanability;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.flex.pmd.nodes.IClass;
+import org.apache.flex.pmd.rules.core.AbstractAstFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+/**
+ * @author xagnetti
+ */
+public class ClassAndExtensionAreIdenticalRule extends AbstractAstFlexRule {
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#findViolations(com.adobe
+ * .ac.pmd.nodes.IClass)
+ */
+ @Override
+ protected final void findViolations(final IClass classNode) {
+ final String extensionName = classNode.getExtensionName();
+
+ if (extensionName != null) {
+ final String extension = extractExtensionName(extensionName);
+
+ if (extension.equals(classNode.getName())) {
+ addViolation(classNode);
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority()
+ */
+ @Override
+ protected final ViolationPriority getDefaultPriority() {
+ return ViolationPriority.HIGH;
+ }
+
+ private String extractExtensionName(final String extensionName) {
+ return extensionName.indexOf('.') == -1 ? extensionName
+ : StringUtils.substringAfterLast(extensionName,
+ ".");
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/DynamicClassRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/DynamicClassRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/DynamicClassRule.java
new file mode 100644
index 0000000..608c092
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/DynamicClassRule.java
@@ -0,0 +1,60 @@
+/*
+ * 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 org.apache.flex.pmd.rules.maintanability;
+
+import org.apache.flex.pmd.nodes.IClass;
+import org.apache.flex.pmd.nodes.Modifier;
+import org.apache.flex.pmd.rules.core.AbstractAstFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+/**
+ * @author xagnetti
+ */
+public class DynamicClassRule extends AbstractAstFlexRule {
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#isConcernedByTheCurrentFile
+ * ()
+ */
+ @Override
+ public final boolean isConcernedByTheCurrentFile() {
+ return !getCurrentFile().isMxml();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#findViolations(com.adobe
+ * .ac.pmd.nodes.IClass)
+ */
+ @Override
+ protected final void findViolations(final IClass classNode) {
+ if (classNode.is(Modifier.DYNAMIC)) {
+ addViolation(classNode);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority()
+ */
+ @Override
+ protected final ViolationPriority getDefaultPriority() {
+ return ViolationPriority.HIGH;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/EmptyStatementRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/EmptyStatementRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/EmptyStatementRule.java
new file mode 100644
index 0000000..918b9aa
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/EmptyStatementRule.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 org.apache.flex.pmd.rules.maintanability;
+
+import org.apache.flex.pmd.parser.IParserNode;
+import org.apache.flex.pmd.rules.core.AbstractAstFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+/**
+ * @author xagnetti
+ */
+public class EmptyStatementRule extends AbstractAstFlexRule {
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority()
+ */
+ @Override
+ protected ViolationPriority getDefaultPriority() {
+ return ViolationPriority.LOW;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#visitEmptyStatetement(
+ * com.adobe.ac.pmd.parser.IParserNode)
+ */
+ @Override
+ protected void visitEmptyStatetement(final IParserNode statementNode) {
+ addViolation(statementNode);
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/ExcessiveImportRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/ExcessiveImportRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/ExcessiveImportRule.java
new file mode 100644
index 0000000..3979310
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/ExcessiveImportRule.java
@@ -0,0 +1,74 @@
+/*
+ * 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 org.apache.flex.pmd.rules.maintanability;
+
+import org.apache.flex.pmd.nodes.IPackage;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+import org.apache.flex.pmd.rules.core.thresholded.AbstractMaximizedAstFlexRule;
+
+/**
+ * @author xagnetti
+ */
+public class ExcessiveImportRule extends AbstractMaximizedAstFlexRule {
+ private static final int DEFAULT_THRESHOLD = 15;
+ private int importNumber;
+
+ /*
+ * (non-Javadoc)
+ * @seecom.adobe.ac.pmd.rules.core.thresholded.IThresholdedRule#
+ * getActualValueForTheCurrentViolation()
+ */
+ @Override
+ public final int getActualValueForTheCurrentViolation() {
+ return importNumber;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.thresholded.IThresholdedRule#getDefaultThreshold
+ * ()
+ */
+ @Override
+ public final int getDefaultThreshold() {
+ return DEFAULT_THRESHOLD;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#findViolations(com.adobe
+ * .ac.pmd.nodes.IPackage)
+ */
+ @Override
+ protected final void findViolations(final IPackage packageNode) {
+ importNumber = packageNode.getImports().size();
+
+ if (importNumber > getThreshold()) {
+ addViolation(packageNode.getClassNode());
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority()
+ */
+ @Override
+ protected final ViolationPriority getDefaultPriority() {
+ return ViolationPriority.NORMAL;
+ }
+}
[14/24] git commit: [flex-utilities]
[refs/heads/feature/pmd-5.2-language-module] - Initial commit of the PMD
language module for Apache Flex
Posted by cd...@apache.org.
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/NonStaticConstantFieldRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/NonStaticConstantFieldRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/NonStaticConstantFieldRule.java
new file mode 100644
index 0000000..1686b96
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/NonStaticConstantFieldRule.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.flex.pmd.rules.maintanability;
+
+import org.apache.flex.pmd.nodes.IConstant;
+import org.apache.flex.pmd.rules.core.AbstractAstFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+import java.util.List;
+
+/**
+ * @author xagnetti
+ */
+public class NonStaticConstantFieldRule extends AbstractAstFlexRule {
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#findViolationsFromConstants
+ * (java.util.List)
+ */
+ @Override
+ protected final void findViolationsFromConstants(final List<IConstant> constants) {
+ for (final IConstant field : constants) {
+ if (!field.isStatic()
+ && field.isPublic()) {
+ addViolation(field,
+ field.getName());
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority()
+ */
+ @Override
+ protected final ViolationPriority getDefaultPriority() {
+ return ViolationPriority.LOW;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/OnlyOneReturnRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/OnlyOneReturnRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/OnlyOneReturnRule.java
new file mode 100644
index 0000000..15391e0
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/OnlyOneReturnRule.java
@@ -0,0 +1,67 @@
+/*
+ * 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 org.apache.flex.pmd.rules.maintanability;
+
+import org.apache.flex.pmd.parser.IParserNode;
+import org.apache.flex.pmd.rules.core.AbstractAstFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+/**
+ * @author xagnetti
+ */
+public class OnlyOneReturnRule extends AbstractAstFlexRule {
+ private int returnStatement;
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority()
+ */
+ @Override
+ protected ViolationPriority getDefaultPriority() {
+ return ViolationPriority.NORMAL;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#visitFunction(com.adobe
+ * .ac.pmd.parser.IParserNode,
+ * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule.FunctionType)
+ */
+ @Override
+ protected void visitFunction(final IParserNode functionNode,
+ final FunctionType type) {
+ returnStatement = 0;
+ super.visitFunction(functionNode,
+ type);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#visitReturn(com.adobe.
+ * ac.pmd.parser.IParserNode)
+ */
+ @Override
+ protected void visitReturn(final IParserNode ast) {
+ returnStatement++;
+
+ if (returnStatement > 1) {
+ addViolation(ast);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/ProtectedStaticMethodRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/ProtectedStaticMethodRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/ProtectedStaticMethodRule.java
new file mode 100644
index 0000000..2704549
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/ProtectedStaticMethodRule.java
@@ -0,0 +1,50 @@
+/*
+ * 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 org.apache.flex.pmd.rules.maintanability;
+
+import org.apache.flex.pmd.nodes.IFunction;
+import org.apache.flex.pmd.nodes.Modifier;
+import org.apache.flex.pmd.rules.core.AbstractAstFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+/**
+ * @author xagnetti
+ */
+public class ProtectedStaticMethodRule extends AbstractAstFlexRule {
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#findViolations(com.adobe
+ * .ac.pmd.nodes.IFunction)
+ */
+ @Override
+ protected void findViolations(final IFunction function) {
+ if (function.is(Modifier.STATIC)
+ && function.is(Modifier.PROTECTED)) {
+ addViolation(function);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority()
+ */
+ @Override
+ protected ViolationPriority getDefaultPriority() {
+ return ViolationPriority.NORMAL;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/ReferenceToVariableBindingFromItsInitializerRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/ReferenceToVariableBindingFromItsInitializerRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/ReferenceToVariableBindingFromItsInitializerRule.java
new file mode 100644
index 0000000..0a25d33
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/ReferenceToVariableBindingFromItsInitializerRule.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 org.apache.flex.pmd.rules.maintanability;
+
+import org.apache.flex.pmd.nodes.IAttribute;
+import org.apache.flex.pmd.nodes.IConstant;
+import org.apache.flex.pmd.nodes.IField;
+import org.apache.flex.pmd.nodes.IFieldInitialization;
+import org.apache.flex.pmd.parser.IParserNode;
+import org.apache.flex.pmd.rules.core.AbstractAstFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+import java.util.List;
+
+/**
+ * @author xagnetti
+ */
+public class ReferenceToVariableBindingFromItsInitializerRule extends AbstractAstFlexRule {
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#findViolationsFromAttributes
+ * (java.util.List)
+ */
+ @Override
+ protected void findViolationsFromAttributes(final List<IAttribute> variables) {
+ for (final IAttribute attribute : variables) {
+ findViolation(attribute);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#findViolationsFromConstants
+ * (java.util.List)
+ */
+ @Override
+ protected void findViolationsFromConstants(final List<IConstant> constants) {
+ for (final IConstant constant : constants) {
+ findViolation(constant);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority()
+ */
+ @Override
+ protected ViolationPriority getDefaultPriority() {
+ return ViolationPriority.HIGH;
+ }
+
+ private void findViolation(final IField attribute) {
+ final IFieldInitialization initialization = attribute.getInitializationExpression();
+ final String name = attribute.getName();
+
+ if (initialization != null) {
+ final List<IParserNode> statements = initialization.getInternalNode()
+ .findPrimaryStatementsFromNameInChildren(new String[]
+ {name});
+ if (statements != null
+ && !statements.isEmpty()) {
+ addViolation(attribute);
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/TrueFalseConditionRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/TrueFalseConditionRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/TrueFalseConditionRule.java
new file mode 100644
index 0000000..960db39
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/TrueFalseConditionRule.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 org.apache.flex.pmd.rules.maintanability;
+
+import org.apache.flex.pmd.parser.IParserNode;
+import org.apache.flex.pmd.rules.core.AbstractAstFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+/**
+ * @author xagnetti
+ */
+public class TrueFalseConditionRule extends AbstractAstFlexRule // NO_UCD
+{
+ private static final int FALSE = 2;
+ private static final int TRUE = 1;
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority()
+ */
+ @Override
+ protected ViolationPriority getDefaultPriority() {
+ return ViolationPriority.HIGH;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#visitCondition(com.adobe
+ * .ac.pmd.parser.IParserNode)
+ */
+ @Override
+ protected void visitCondition(final IParserNode condition) {
+ super.visitCondition(condition);
+
+ final int conditionChidrenHaveBooleans = conditionChidrenHaveBooleans(condition);
+
+ if (conditionChidrenHaveBooleans > 0) {
+ addViolation(condition,
+ (conditionChidrenHaveBooleans == TRUE ? ""
+ : "!")
+ + "condition");
+ }
+ }
+
+ private int conditionChidrenHaveBooleans(final IParserNode condition) {
+ if (condition != null) {
+ for (final IParserNode child : condition.getChildren()) {
+ if (child.getStringValue() != null) {
+ if (child.getStringValue().compareTo("true") == 0) {
+ return TRUE;
+ }
+ if (child.getStringValue().compareTo("false") == 0) {
+ return FALSE;
+ }
+ }
+ }
+ }
+ return 0;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/UselessOverridenFunctionRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/UselessOverridenFunctionRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/UselessOverridenFunctionRule.java
new file mode 100644
index 0000000..b3f524d
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/UselessOverridenFunctionRule.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 org.apache.flex.pmd.rules.maintanability;
+
+import org.apache.flex.pmd.nodes.IFunction;
+import org.apache.flex.pmd.parser.IParserNode;
+import org.apache.flex.pmd.parser.KeyWords;
+import org.apache.flex.pmd.rules.core.AbstractAstFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+import java.util.List;
+
+/**
+ * @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/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/forbiddentypes/AbstractUseForbiddenTypeRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/forbiddentypes/AbstractUseForbiddenTypeRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/forbiddentypes/AbstractUseForbiddenTypeRule.java
new file mode 100644
index 0000000..9dcbfc2
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/forbiddentypes/AbstractUseForbiddenTypeRule.java
@@ -0,0 +1,105 @@
+/*
+ * 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 org.apache.flex.pmd.rules.maintanability.forbiddentypes;
+
+import org.apache.flex.pmd.nodes.IClass;
+import org.apache.flex.pmd.nodes.IFunction;
+import org.apache.flex.pmd.nodes.IVariable;
+import org.apache.flex.pmd.parser.IParserNode;
+import org.apache.flex.pmd.rules.core.AbstractAstFlexRule;
+
+import java.util.List;
+import java.util.Map.Entry;
+
+/**
+ * @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/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/forbiddentypes/UseDictionaryTypeRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/forbiddentypes/UseDictionaryTypeRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/forbiddentypes/UseDictionaryTypeRule.java
new file mode 100644
index 0000000..f491623
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/forbiddentypes/UseDictionaryTypeRule.java
@@ -0,0 +1,44 @@
+/*
+ * 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 org.apache.flex.pmd.rules.maintanability.forbiddentypes;
+
+import org.apache.flex.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/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/forbiddentypes/UseGenericTypeRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/forbiddentypes/UseGenericTypeRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/forbiddentypes/UseGenericTypeRule.java
new file mode 100644
index 0000000..dbb3f75
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/forbiddentypes/UseGenericTypeRule.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 org.apache.flex.pmd.rules.maintanability.forbiddentypes;
+
+import org.apache.flex.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/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/forbiddentypes/UseObjectTypeRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/forbiddentypes/UseObjectTypeRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/forbiddentypes/UseObjectTypeRule.java
new file mode 100644
index 0000000..f095ef9
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/maintanability/forbiddentypes/UseObjectTypeRule.java
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.flex.pmd.rules.maintanability.forbiddentypes;
+
+import org.apache.flex.pmd.nodes.IClass;
+import org.apache.flex.pmd.nodes.IFunction;
+import org.apache.flex.pmd.parser.IParserNode;
+import org.apache.flex.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/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/multitouch/AvoidRollMouseEventRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/multitouch/AvoidRollMouseEventRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/multitouch/AvoidRollMouseEventRule.java
new file mode 100644
index 0000000..b1062b4
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/multitouch/AvoidRollMouseEventRule.java
@@ -0,0 +1,64 @@
+/*
+ * 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 org.apache.flex.pmd.rules.multitouch;
+
+import org.apache.flex.pmd.rules.core.AbstractRegexpBasedRule;
+import org.apache.flex.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/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/multitouch/AvoidTooltipRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/multitouch/AvoidTooltipRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/multitouch/AvoidTooltipRule.java
new file mode 100644
index 0000000..baf0314
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/multitouch/AvoidTooltipRule.java
@@ -0,0 +1,63 @@
+/*
+ * 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 org.apache.flex.pmd.rules.multitouch;
+
+import org.apache.flex.pmd.rules.core.AbstractRegexpBasedRule;
+import org.apache.flex.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/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/mxml/AbstractMoreThanEntryPointInMxmlRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/mxml/AbstractMoreThanEntryPointInMxmlRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/mxml/AbstractMoreThanEntryPointInMxmlRule.java
new file mode 100644
index 0000000..1c3cb7e
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/mxml/AbstractMoreThanEntryPointInMxmlRule.java
@@ -0,0 +1,101 @@
+/*
+ * 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 org.apache.flex.pmd.rules.mxml;
+
+import org.apache.flex.pmd.nodes.IAttribute;
+import org.apache.flex.pmd.nodes.IClass;
+import org.apache.flex.pmd.nodes.IFunction;
+import org.apache.flex.pmd.rules.core.AbstractAstFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+import java.util.List;
+
+/**
+ * @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/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/mxml/CodeBehindInMxmlRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/mxml/CodeBehindInMxmlRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/mxml/CodeBehindInMxmlRule.java
new file mode 100644
index 0000000..4789dcb
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/mxml/CodeBehindInMxmlRule.java
@@ -0,0 +1,63 @@
+/*
+ * 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 org.apache.flex.pmd.rules.mxml;
+
+import org.apache.flex.pmd.rules.core.AbstractRegexpBasedRule;
+import org.apache.flex.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/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/mxml/MoreThanOneEntryPointInMxmlRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/mxml/MoreThanOneEntryPointInMxmlRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/mxml/MoreThanOneEntryPointInMxmlRule.java
new file mode 100644
index 0000000..fe5d52e
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/mxml/MoreThanOneEntryPointInMxmlRule.java
@@ -0,0 +1,44 @@
+/*
+ * 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 org.apache.flex.pmd.rules.mxml;
+
+import org.apache.flex.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/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/mxml/MoreThanTwoEntryPointsInMxmlRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/mxml/MoreThanTwoEntryPointsInMxmlRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/mxml/MoreThanTwoEntryPointsInMxmlRule.java
new file mode 100644
index 0000000..ca034fc
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/mxml/MoreThanTwoEntryPointsInMxmlRule.java
@@ -0,0 +1,44 @@
+/*
+ * 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 org.apache.flex.pmd.rules.mxml;
+
+import org.apache.flex.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/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/mxml/OnlyOneScriptBlockPerMxmlRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/mxml/OnlyOneScriptBlockPerMxmlRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/mxml/OnlyOneScriptBlockPerMxmlRule.java
new file mode 100644
index 0000000..d26f7b1
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/mxml/OnlyOneScriptBlockPerMxmlRule.java
@@ -0,0 +1,89 @@
+/*
+ * 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 org.apache.flex.pmd.rules.mxml;
+
+import org.apache.flex.pmd.rules.IFlexViolation;
+import org.apache.flex.pmd.rules.core.AbstractXpathRelatedRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+import org.w3c.dom.Document;
+
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpressionException;
+import java.util.List;
+
+/**
+ * @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/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/mxml/StaticMethodInMxmlRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/mxml/StaticMethodInMxmlRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/mxml/StaticMethodInMxmlRule.java
new file mode 100644
index 0000000..255d1db
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/mxml/StaticMethodInMxmlRule.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 org.apache.flex.pmd.rules.mxml;
+
+import org.apache.flex.pmd.nodes.IFunction;
+import org.apache.flex.pmd.nodes.Modifier;
+import org.apache.flex.pmd.rules.core.AbstractAstFlexRule;
+import org.apache.flex.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/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/mxml/TooLongScriptBlockRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/mxml/TooLongScriptBlockRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/mxml/TooLongScriptBlockRule.java
new file mode 100644
index 0000000..349a0bc
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/mxml/TooLongScriptBlockRule.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 org.apache.flex.pmd.rules.mxml;
+
+import org.apache.flex.pmd.files.IMxmlFile;
+import org.apache.flex.pmd.rules.IFlexViolation;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+import org.apache.flex.pmd.rules.core.thresholded.AbstractMaximizedFlexRule;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @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/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/mxml/TooManyStatesInMxmlRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/mxml/TooManyStatesInMxmlRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/mxml/TooManyStatesInMxmlRule.java
new file mode 100644
index 0000000..ae80b69
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/mxml/TooManyStatesInMxmlRule.java
@@ -0,0 +1,135 @@
+/*
+ * 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 org.apache.flex.pmd.rules.mxml;
+
+import net.sourceforge.pmd.PropertyDescriptor;
+import org.apache.flex.pmd.rules.IFlexViolation;
+import org.apache.flex.pmd.rules.core.AbstractXpathRelatedRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+import org.apache.flex.pmd.rules.core.thresholded.IThresholdedRule;
+import org.w3c.dom.Document;
+
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpressionException;
+import java.util.List;
+
+/**
+ * @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 getProperty((PropertyDescriptor<Integer>) getPropertyDescriptor(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()));
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/naming/BooleanAttributeShouldContainIsHasRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/naming/BooleanAttributeShouldContainIsHasRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/naming/BooleanAttributeShouldContainIsHasRule.java
new file mode 100644
index 0000000..cff8d3a
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/naming/BooleanAttributeShouldContainIsHasRule.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.flex.pmd.rules.naming;
+
+import org.apache.flex.pmd.nodes.IAttribute;
+import org.apache.flex.pmd.nodes.IFunction;
+import org.apache.flex.pmd.nodes.INamableNode;
+import org.apache.flex.pmd.rules.core.AbstractAstFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+import java.util.List;
+
+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/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/naming/CapitalizeConstantsRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/naming/CapitalizeConstantsRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/naming/CapitalizeConstantsRule.java
new file mode 100644
index 0000000..d2a5686
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/naming/CapitalizeConstantsRule.java
@@ -0,0 +1,45 @@
+/*
+ * 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 org.apache.flex.pmd.rules.naming;
+
+import org.apache.flex.pmd.nodes.IConstant;
+import org.apache.flex.pmd.rules.core.AbstractAstFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+import java.util.List;
+import java.util.Locale;
+
+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/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/naming/IncorrectClassCase.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/naming/IncorrectClassCase.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/naming/IncorrectClassCase.java
new file mode 100644
index 0000000..618c5d3
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/naming/IncorrectClassCase.java
@@ -0,0 +1,52 @@
+/*
+ * 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 org.apache.flex.pmd.rules.naming;
+
+import org.apache.flex.pmd.nodes.IClass;
+import org.apache.flex.pmd.rules.core.AbstractAstFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+import org.apache.flex.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/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/naming/IncorrectEventHandlerNameRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/naming/IncorrectEventHandlerNameRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/naming/IncorrectEventHandlerNameRule.java
new file mode 100644
index 0000000..a901685
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/naming/IncorrectEventHandlerNameRule.java
@@ -0,0 +1,67 @@
+/*
+ * 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 org.apache.flex.pmd.rules.naming;
+
+import net.sourceforge.pmd.lang.rule.properties.StringProperty;
+import org.apache.flex.pmd.nodes.IFunction;
+import org.apache.flex.pmd.parser.IParserNode;
+import org.apache.flex.pmd.rules.core.AbstractAstFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+public class IncorrectEventHandlerNameRule extends AbstractAstFlexRule {
+
+ private static final StringProperty PREFIX_DESCRIPTOR = new StringProperty(
+ "prefix",
+ "",
+ "on",
+ 1.0f
+ );
+ private static final StringProperty SUFFIX_DESCRIPTOR = new StringProperty(
+ "suffix",
+ "",
+ "",
+ 1.0f
+ );
+
+ private final String prefix;
+ private final String suffix;
+
+ public IncorrectEventHandlerNameRule() {
+ super();
+ prefix = getProperty(PREFIX_DESCRIPTOR);
+ suffix = getProperty(SUFFIX_DESCRIPTOR);
+ }
+
+ @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;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/naming/InterfaceNamingRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/naming/InterfaceNamingRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/naming/InterfaceNamingRule.java
new file mode 100644
index 0000000..1638d2d
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/naming/InterfaceNamingRule.java
@@ -0,0 +1,37 @@
+/*
+ * 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 org.apache.flex.pmd.rules.naming;
+
+import org.apache.flex.pmd.nodes.IClass;
+import org.apache.flex.pmd.parser.NodeKind;
+import org.apache.flex.pmd.rules.core.AbstractAstFlexRule;
+import org.apache.flex.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/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/naming/PackageCaseRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/naming/PackageCaseRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/naming/PackageCaseRule.java
new file mode 100644
index 0000000..c9833df
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/naming/PackageCaseRule.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 org.apache.flex.pmd.rules.naming;
+
+import org.apache.flex.pmd.nodes.IPackage;
+import org.apache.flex.pmd.rules.IFlexViolation;
+import org.apache.flex.pmd.rules.core.AbstractAstFlexRule;
+import org.apache.flex.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/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/naming/PropertyHiddenByLocalVariableRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/naming/PropertyHiddenByLocalVariableRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/naming/PropertyHiddenByLocalVariableRule.java
new file mode 100644
index 0000000..c968580
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/naming/PropertyHiddenByLocalVariableRule.java
@@ -0,0 +1,67 @@
+/*
+ * 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 org.apache.flex.pmd.rules.naming;
+
+import org.apache.flex.pmd.nodes.IAttribute;
+import org.apache.flex.pmd.nodes.IClass;
+import org.apache.flex.pmd.nodes.IFunction;
+import org.apache.flex.pmd.nodes.IVariable;
+import org.apache.flex.pmd.rules.core.AbstractAstFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+import java.util.List;
+import java.util.Set;
+
+/**
+ * @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/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/naming/TooLongFunctionNameRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/naming/TooLongFunctionNameRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/naming/TooLongFunctionNameRule.java
new file mode 100644
index 0000000..60b255d
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/naming/TooLongFunctionNameRule.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.flex.pmd.rules.naming;
+
+import org.apache.flex.pmd.nodes.IFunction;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+import org.apache.flex.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;
+ }
+}
[21/24] git commit: [flex-utilities]
[refs/heads/feature/pmd-5.2-language-module] - Initial commit of the PMD
language module for Apache Flex
Posted by cd...@apache.org.
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestCompilationUnit.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestCompilationUnit.java b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestCompilationUnit.java
new file mode 100644
index 0000000..a59d9c3
--- /dev/null
+++ b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestCompilationUnit.java
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.flex.pmd.parser.impl;
+
+import static org.testng.Assert.*;
+
+import org.apache.flex.pmd.parser.exceptions.TokenException;
+import org.testng.annotations.Test;
+
+public class TestCompilationUnit extends AbstractAs3ParserTestBase {
+
+ @Test
+ public void testEmptyPackage() throws TokenException {
+ assertCompilationUnit("1",
+ "package a { } ",
+ "<compilation-unit line=\"-1\">"
+ + "<package line=\"1\">" + "<name line=\"1\">a"
+ + "</name><content line=\"1\">"
+ + "</content></package><content line=\"2\">"
+ + "</content></compilation-unit>");
+ }
+
+ @Test
+ public void testEmptyPackagePlusLocalClass() throws TokenException {
+ assertCompilationUnit("1",
+ "package a { } class Local { }",
+ "<compilation-unit line=\"-1\"><package line=\"1\">"
+ + "<name line=\"1\">a</name><content line=\"1\">"
+ + "</content></package><content line=\"1\"><class line=\"1\""
+ + "><name line=\"1\">Local</name>"
+ + "<mod-list line=\"1\"></mod-list><content line=\"1\">"
+ + "</content></class></content></compilation-unit>");
+ }
+
+ @Test
+ public void testPackageWithClass() throws TokenException {
+ assertCompilationUnit("1",
+ "package a { public class B { } } ",
+ "<compilation-unit line=\"-1\"><package line=\"1\">"
+ + "<name line=\"1\">a</name><content line=\"1\">"
+ + "<class line=\"1\"><name line=\"1\">B</name>"
+ + "<mod-list line=\"1\"><mod line=\"1\">public"
+ + "</mod></mod-list><content line=\"1\"></content>"
+ + "</class></content></package><content line=\"2\">"
+ + "</content></compilation-unit>");
+ }
+
+ @Test
+ public void testPackageWithInterface() throws TokenException {
+ assertCompilationUnit("1",
+ "package a { public interface B { } } ",
+ "<compilation-unit line=\"-1\"><package line=\"1\">"
+ + "<name line=\"1\">a</name><content line=\"1\">"
+ + "<interface line=\"1\"><name line=\"1\">B</name>"
+ + "<mod-list line=\"1\"><mod line=\"1\">public</mod>"
+ + "</mod-list><content line=\"1\"></content></interface>"
+ + "</content></package><content line=\"2\"></content>"
+ + "</compilation-unit>");
+ }
+
+ private void assertCompilationUnit(final String message,
+ final String input,
+ final String expected) throws TokenException {
+ scn.setLines(new String[]
+ {input,
+ "__END__"});
+ final String result = new ASTToXMLConverter().convert(asp.parseCompilationUnit());
+ assertEquals(expected, result, message);
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestConstStatement.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestConstStatement.java b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestConstStatement.java
new file mode 100644
index 0000000..5743275
--- /dev/null
+++ b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestConstStatement.java
@@ -0,0 +1,62 @@
+/*
+ * 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 org.apache.flex.pmd.parser.impl;
+
+import org.apache.flex.pmd.parser.exceptions.TokenException;
+import org.testng.annotations.Test;
+
+public class TestConstStatement extends AbstractStatementTestBase {
+
+ @Test
+ public void testFullFeaturedConst() throws TokenException {
+ assertStatement("1",
+ "const a : int = 4",
+ "<const-list line=\"1\">"
+ + "<name-type-init line=\"1\">"
+ + "<name line=\"1\">a</name><type line=\"1\">int</type>"
+ + "<init line=\"1\"><primary line=\"1\">4</primary>"
+ + "</init></name-type-init></const-list>");
+ }
+
+ @Test
+ public void testInitializedConst() throws TokenException {
+ assertStatement("1",
+ "const a = 4",
+ "<const-list line=\"1\"><name-type-init line=\"1\">"
+ + "<name line=\"1\">a</name><type line=\"1\">"
+ + "</type><init line=\"1\"><primary line=\"1\">4"
+ + "</primary></init></name-type-init></const-list>");
+ }
+
+ @Test
+ public void testSimpleConst() throws TokenException {
+ assertStatement("1",
+ "const a",
+ "<const-list line=\"1\"><name-type-init line=\"1\">"
+ + "<name line=\"1\">a</name><type line=\"2\">"
+ + "</type></name-type-init></const-list>");
+ }
+
+ @Test
+ public void testTypedConst() throws TokenException {
+ assertStatement("1",
+ "const a : Object",
+ "<const-list line=\"1\"><name-type-init line=\"1\">"
+ + "<name line=\"1\">a</name><type line=\"1\">Object</type>"
+ + "</name-type-init></const-list>");
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestDoStatement.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestDoStatement.java b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestDoStatement.java
new file mode 100644
index 0000000..d650f0a
--- /dev/null
+++ b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestDoStatement.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.flex.pmd.parser.impl;
+
+import org.apache.flex.pmd.parser.exceptions.TokenException;
+import org.testng.annotations.Test;
+
+public class TestDoStatement extends AbstractStatementTestBase {
+
+ @Test
+ public void testDo() throws TokenException {
+ assertStatement("1",
+ "do{ trace( i ); } while( i++ );",
+ "<do line=\"1\"><block line=\"1\">"
+ + "<call line=\"1\"><primary line=\"1\">"
+ + "trace</primary><arguments line=\"1\">"
+ + "<primary line=\"1\">i</primary></arguments>"
+ + "</call></block><condition line=\"1\">"
+ + "<post-inc line=\"1\"><primary line=\"1\">"
+ + "i</primary></post-inc></condition></do>");
+ }
+
+ @Test
+ public void testDoWithEmptyStatement() throws TokenException {
+ assertStatement("1",
+ "do ; while( i++ ); ",
+ "<do line=\"1\"><stmt-empty line=\"1\">;</stmt-empty>"
+ + "<condition line=\"1\"><post-inc line=\"1\">"
+ + "<primary line=\"1\">i</primary></post-inc></condition></do>");
+ }
+
+ @Test
+ public void testDoWithoutBlock() throws TokenException {
+ assertStatement("1",
+ "do trace( i ); while( i++ ); ",
+ "<do line=\"1\"><call line=\"1\">"
+ + "<primary line=\"1\">trace</primary><arguments line=\"1\""
+ + "><primary line=\"1\">i</primary>"
+ + "</arguments></call><condition line=\"1\">"
+ + "<post-inc line=\"1\"><primary line=\"1\""
+ + ">i</primary></post-inc></condition></do>");
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestE4xExpression.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestE4xExpression.java b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestE4xExpression.java
new file mode 100644
index 0000000..3ad142a
--- /dev/null
+++ b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestE4xExpression.java
@@ -0,0 +1,44 @@
+/*
+ * 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 org.apache.flex.pmd.parser.impl;
+
+import org.apache.flex.pmd.parser.exceptions.TokenException;
+import org.testng.annotations.Test;
+
+public class TestE4xExpression extends AbstractStatementTestBase {
+
+ @Test
+ public void testE4xFilter() throws TokenException {
+ assertStatement("",
+ "myXml.(lala=\"lala\")",
+ "<e4x-filter line=\"1\"><primary line=\"1\">myXml"
+ + "</primary><assign line=\"1\"><primary line=\"1\">"
+ + "lala</primary><op line=\"1\">=</op><primary line=\"1\">"
+ + "\"lala\"</primary></assign></e4x-filter>");
+
+ assertStatement("",
+ "doc.*.worm[1]",
+ "<mul line=\"1\"><e4x-star line=\"1\"><primary line=\"1\""
+ + ">doc</primary></e4x-star><op line=\"1\">*</op><primary "
+ + "line=\"1\">.</primary></mul>");
+
+ assertStatement("",
+ "doc.@worm",
+ "<dot line=\"1\"><primary line=\"1\">doc</primary><primary "
+ + "line=\"1\">@worm</primary></dot>");
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestEmptyStatement.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestEmptyStatement.java b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestEmptyStatement.java
new file mode 100644
index 0000000..454744a
--- /dev/null
+++ b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestEmptyStatement.java
@@ -0,0 +1,39 @@
+/*
+ * 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 org.apache.flex.pmd.parser.impl;
+
+import org.apache.flex.pmd.parser.exceptions.TokenException;
+import org.testng.annotations.Test;
+
+public class TestEmptyStatement extends AbstractStatementTestBase {
+
+ @Test
+ public void testComplex() throws TokenException {
+ assertStatement("1",
+ "{;1;;}",
+ "<block line=\"1\"><stmt-empty line=\"1\">;"
+ + "</stmt-empty><primary line=\"1\">1"
+ + "</primary><stmt-empty line=\"1\">;</stmt-empty></block>");
+ }
+
+ @Test
+ public void testSimple() throws TokenException {
+ assertStatement("1",
+ ";",
+ "<stmt-empty line=\"1\">;</stmt-empty>");
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestExpression.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestExpression.java b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestExpression.java
new file mode 100644
index 0000000..bda05e8
--- /dev/null
+++ b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestExpression.java
@@ -0,0 +1,186 @@
+/*
+ * 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 org.apache.flex.pmd.parser.impl;
+
+import org.apache.flex.pmd.parser.exceptions.TokenException;
+import org.testng.annotations.Test;
+
+public class TestExpression extends AbstractStatementTestBase {
+
+ @Test
+ public void testAddExpression() throws TokenException {
+ assertStatement("1",
+ "5+6",
+ "<add line=\"1\"><primary line=\"1\""
+ + ">5</primary><op line=\"1\">+</op>" + "<primary line=\"1\">6</primary></add>");
+ }
+
+ @Test
+ public void testAndExpression() throws TokenException {
+ assertStatement("1",
+ "5&&6",
+ "<and line=\"1\"><primary line=\"1\">5</primary>"
+ + "<op line=\"1\">&&</op>" + "<primary line=\"1\">6</primary></and>");
+ }
+
+ @Test
+ public void testAssignmentExpression() throws TokenException {
+ assertStatement("1",
+ "x+=6",
+ "<assign line=\"1\"><primary line=\"1\">x"
+ + "</primary><op line=\"1\">+=</op><primary line=\"1\""
+ + ">6</primary></assign>");
+ }
+
+ @Test
+ public void testBitwiseAndExpression() throws TokenException {
+ assertStatement("1",
+ "5&6",
+ "<b-and line=\"1\"><primary line=\"1\">5"
+ + "</primary><op line=\"1\">&</op><primary line=\"1\">6</primary></b-and>");
+ }
+
+ @Test
+ public void testBitwiseOrExpression() throws TokenException {
+ assertStatement("1",
+ "5|6",
+ "<b-or line=\"1\"><primary line=\"1\">5"
+ + "</primary><op line=\"1\">|</op><primary line=\"1\">6</primary></b-or>");
+ }
+
+ @Test
+ public void testBitwiseXorExpression() throws TokenException {
+ assertStatement("1",
+ "5^6",
+ "<b-xor line=\"1\"><primary line=\"1\">5"
+ + "</primary><op line=\"1\">^</op><primary line=\"1\">6</primary></b-xor>");
+ }
+
+ @Test
+ public void testConditionalExpression() throws TokenException {
+ assertStatement("1",
+ "true?5:6",
+ "<conditional line=\"1\"><primary line=\"1\">"
+ + "true</primary><primary line=\"1\">5" + "</primary><primary line=\"1\">6"
+ + "</primary></conditional>");
+ }
+
+ @Test
+ public void testDivision() throws TokenException {
+ assertStatement("",
+ "offset = ( this[ axis.unscaled ] / 2 - ( rightPos ) / 2 );",
+ "<assign line=\"1\"><primary line=\"1\">offset</primary><op line=\"1\">=</op>"
+ + "<primary line=\"1\"><encapsulated line=\"1\"><add line=\"1\"><mul line=\"1\">"
+ + "<arr-acc line=\"1\"><primary line=\"1\">this</primary><dot line=\"1\"><primary "
+ + "line=\"1\">axis</primary><primary line=\"1\">unscaled</primary></dot></arr-acc>"
+ + "<op line=\"1\">/</op><primary line=\"1\">2</primary></mul><op line=\"1\">-</op>"
+ + "<mul line=\"1\"><primary line=\"1\"><encapsulated line=\"1\"><primary line=\"1\">"
+ + "rightPos</primary></encapsulated></primary><op line=\"1\">/</op><primary line=\"1\">"
+ + "2</primary></mul></add></encapsulated></primary></assign>");
+ }
+
+ @Test
+ public void testEncapsulated() throws TokenException {
+ assertStatement("",
+ "(dataProvider as ArrayCollection) = null",
+ "<assign line=\"1\"><primary line=\"1\">"
+ + "<encapsulated line=\"1\"><relation line=\"1\">"
+ + "<primary line=\"1\">dataProvider</primary>"
+ + "<as line=\"1\">as</as><primary line=\"1\">"
+ + "ArrayCollection</primary></relation></encapsulated></primary>"
+ + "<op line=\"1\">=</op><primary line=\"1\">" + "null</primary></assign>");
+ }
+
+ @Test
+ public void testEqualityExpression() throws TokenException {
+ assertStatement("1",
+ "5!==6",
+ "<equality line=\"1\"><primary line=\"1\">5"
+ + "</primary><op line=\"1\">!==</op><primary line=\"1\">6</primary></equality>");
+ }
+
+ @Test
+ public void testExpressionList() throws TokenException {
+ assertStatement("1",
+ "5&&6,5&&9",
+ "<expr-list line=\"1\"><and line=\"1\">"
+ + "<primary line=\"1\">5</primary><op line=\"1\">"
+ + "&&</op><primary line=\"1\">6</primary></and><and line=\"1\""
+ + "><primary line=\"1\">5</primary><op line=\"1\""
+ + ">&&</op><primary line=\"1\">9</primary></and></expr-list>");
+ }
+
+ @Test
+ public void testInstanceOf() throws TokenException {
+ assertStatement("bug237",
+ "if (a instanceof b){}",
+ "<if line=\"1\"><condition line=\"1\"><relation line=\"1\"><primary "
+ + "line=\"1\">a</primary><op line=\"1\">instanceof</op><primary line=\"1\">"
+ + "b</primary></relation></condition><block line=\"1\"></block></if>");
+ }
+
+ @Test
+ public void testMulExpression() throws TokenException {
+ assertStatement("1",
+ "5/6",
+ "<mul line=\"1\"><primary line=\"1\">5"
+ + "</primary><op line=\"1\">/</op><primary line=\"1\">6</primary></mul>");
+ }
+
+ @Test
+ public void testNewExpression() throws TokenException {
+ assertStatement("",
+ "new Event()",
+ "<new line=\"1\"><call line=\"1\">"
+ + "<primary line=\"1\">Event</primary>"
+ + "<arguments line=\"1\"></arguments></call></new>");
+
+ assertStatement("",
+ "new Event(\"lala\")",
+ "<new line=\"1\"><call line=\"1\">"
+ + "<primary line=\"1\">Event</primary>"
+ + "<arguments line=\"1\"><primary line=\"1\">"
+ + "\"lala\"</primary></arguments></call></new>");
+
+ }
+
+ @Test
+ public void testOrExpression() throws TokenException {
+ assertStatement("1",
+ "5||6",
+ "<or line=\"1\"><primary line=\"1\">5"
+ + "</primary><op line=\"1\">||</op><primary line=\"1\">6</primary></or>");
+ }
+
+ @Test
+ public void testRelationalExpression() throws TokenException {
+ assertStatement("1",
+ "5<=6",
+ "<relation line=\"1\"><primary line=\"1\">5"
+ + "</primary><op line=\"1\"><=</op><primary line=\"1\""
+ + ">6</primary></relation>");
+ }
+
+ @Test
+ public void testShiftExpression() throws TokenException {
+ assertStatement("1",
+ "5<<6",
+ "<shift line=\"1\"><primary line=\"1\">5"
+ + "</primary><op line=\"1\"><<</op><primary line=\"1\""
+ + ">6</primary></shift>");
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestForStatement.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestForStatement.java b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestForStatement.java
new file mode 100644
index 0000000..8560c13
--- /dev/null
+++ b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestForStatement.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 org.apache.flex.pmd.parser.impl;
+
+import org.apache.flex.pmd.parser.exceptions.TokenException;
+import org.testng.annotations.Test;
+
+public class TestForStatement extends AbstractStatementTestBase {
+
+ @Test
+ public void testSimpleFor() throws TokenException {
+ assertStatement("1",
+ "for( var i : int = 0; i < length; i++ ){ trace( i ); }",
+ "<for line=\"1\"><init line=\"1\">"
+ + "<var-list line=\"1\"><name-type-init line=\"1\""
+ + "><name line=\"1\">i</name><type line=\"1\">int</type><init line=\"1\">"
+ + "<primary line=\"1\">0</primary></init>"
+ + "</name-type-init></var-list></init>"
+ + "<cond line=\"1\"><relation line=\"1\">"
+ + "<primary line=\"1\">i</primary><op line=\"1\""
+ + "><</op><primary line=\"1\">length"
+ + "</primary></relation></cond><iter line=\"1\">"
+ + "<post-inc line=\"1\"><primary line=\"1\">i"
+ + "</primary></post-inc></iter><block line=\"1\"><call line=\"1\""
+ + "><primary line=\"1\">trace"
+ + "</primary><arguments line=\"1\"><primary line=\"1\">i"
+ + "</primary></arguments></call></block></for>");
+
+ assertStatement("",
+ " for (i = 0; i < n; i++)",
+ "<for line=\"1\"><init line=\"1\">"
+ + "<assign line=\"1\"><primary line=\"1\">i</primary><op line=\"1\">=</op>"
+ + "<primary line=\"1\">0</primary></assign></init>"
+ + "<cond line=\"1\"><relation line=\"1\"><primary line=\"1\">i</primary>"
+ + "<op line=\"1\"><</op><primary line=\"1\">n"
+ + "</primary></relation></cond><iter line=\"1\">"
+ + "<post-inc line=\"1\"><primary line=\"1\">i"
+ + "</primary></post-inc></iter><primary line=\"2\">__END__</primary></for>");
+ }
+
+ @Test
+ public void testSimpleForEach() throws TokenException {
+ assertStatement("1",
+ "for each( var obj : Object in list ){ obj.print( i ); }",
+ "<foreach line=\"1\"><var line=\"1\">"
+ + "<name-type-init line=\"1\"><name line=\"1\""
+ + ">obj</name><type line=\"1\">Object"
+ + "</type></name-type-init></var><in line=\"1\">"
+ + "<primary line=\"1\">list</primary></in>"
+ + "<block line=\"1\"><dot line=\"1\">"
+ + "<primary line=\"1\">obj</primary><call line=\"1\""
+ + "><primary line=\"1\">print</primary>"
+ + "<arguments line=\"1\"><primary line=\"1\">"
+ + "i</primary></arguments></call></dot></block></foreach>");
+
+ assertStatement("1",
+ "for each( obj in list ){}",
+ "<foreach line=\"1\"><name line=\"1\">obj</name>"
+ + "<in line=\"1\"><primary line=\"1\">list</primary>"
+ + "</in><block line=\"1\"></block></foreach>");
+
+ // assertStatement(
+ // "", "for each (var a:XML in classInfo..accessor) {}", "" );
+ }
+
+ @Test
+ public void testSimpleForIn() throws TokenException {
+ assertStatement("1",
+ "for( var s : String in obj ){ trace( s, obj[ s ]); }",
+ "<forin line=\"1\"><init line=\"1\">"
+ + "<var-list line=\"1\"><name-type-init line=\"1\""
+ + "><name line=\"1\">s</name>"
+ + "<type line=\"1\">String</type></name-type-init>"
+ + "</var-list></init><in line=\"1\"><primary line=\"1\""
+ + ">obj</primary></in></forin>");
+
+ assertStatement("for in",
+ " for (p in events);",
+ "<forin line=\"1\"><init line=\"1\">"
+ + "<primary line=\"1\">p</primary></init><in line=\"1\""
+ + "><primary line=\"1\">events</primary></in></forin>");
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestIfStatement.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestIfStatement.java b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestIfStatement.java
new file mode 100644
index 0000000..06c2f7f
--- /dev/null
+++ b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestIfStatement.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 org.apache.flex.pmd.parser.impl;
+
+import org.apache.flex.pmd.parser.exceptions.TokenException;
+import org.testng.annotations.Test;
+
+public class TestIfStatement extends AbstractStatementTestBase {
+
+ @Test
+ public void testBug232() throws TokenException {
+ assertStatement("",
+ "if (true || /* comment */!false) ) )",
+ "<if line=\"1\"><condition line=\"1\"><or line=\"1\"><primary line=\"1\">"
+ + "true</primary><op line=\"1\">||</op><not line=\"1\"><primary "
+ + "line=\"1\">false</primary></not></or></condition><primary "
+ + "line=\"1\">)</primary></if>");
+ }
+
+ @Test
+ public void testIf() throws TokenException {
+ assertStatement("1",
+ "if( true ){ trace( true ); }",
+ "<if line=\"1\">"
+ + "<condition line=\"1\">" + "<primary line=\"1\">true</primary></condition>"
+ + "<block line=\"1\"><call line=\"1\">" + "<primary line=\"1\">trace"
+ + "</primary><arguments line=\"1\">" + "<primary line=\"1\">true</primary>"
+ + "</arguments></call></block></if>");
+
+ assertStatement("1",
+ "if( \"i\" in oaderContext ){ }",
+ "<if line=\"1\"><condition line=\"1\">"
+ + "<relation line=\"1\"><primary line=\"1\">"
+ + "\"i\"</primary><op line=\"1\">in</op>"
+ + "<primary line=\"1\">oaderContext</primary>"
+ + "</relation></condition><block line=\"1\"></block></if>");
+
+ assertStatement("internal",
+ "if (col.mx_internal::contentSize) {col.mx_internal::_width = NaN;}",
+ "<if line=\"1\"><condition line=\"1\">"
+ + "<dot line=\"1\"><primary line=\"1\">col"
+ + "</primary><dot line=\"1\"><primary line=\"1\">"
+ + "mx_internal</primary><primary line=\"1\">contentSize"
+ + "</primary></dot></dot></condition><block line=\"1\">"
+ + "<dot line=\"1\"><primary line=\"1\">col"
+ + "</primary><dot line=\"1\"><primary line=\"1\">"
+ + "mx_internal</primary><assign line=\"1\">"
+ + "<primary line=\"1\">_width</primary>"
+ + "<op line=\"1\">=</op><primary line=\"1\">"
+ + "NaN</primary></assign></dot></dot></block></if>");
+ }
+
+ @Test
+ public void testIfElse() throws TokenException {
+ assertStatement("1",
+ "if( true ){ trace( true ); } else { trace( false )}",
+ "<if line=\"1\"><condition line=\"1\">"
+ + "<primary line=\"1\">true" + "</primary></condition><block line=\"1\">"
+ + "<call line=\"1\"><primary line=\"1\">trace"
+ + "</primary><arguments line=\"1\">"
+ + "<primary line=\"1\">true</primary></arguments>"
+ + "</call></block><block line=\"1\">" + "<call line=\"1\">"
+ + "<primary line=\"1\">trace</primary>" + "<arguments line=\"1\">"
+ + "<primary line=\"1\">false</primary>" + "</arguments></call></block></if>");
+ }
+
+ @Test
+ public void testIfWithArrayAccessor() throws TokenException {
+ assertStatement("",
+ "if ( chart.getItemAt( 0 )[ xField ] > targetXFieldValue ){}",
+ "<if line=\"1\"><condition line=\"1\"><dot line=\"1\""
+ + "><primary line=\"1\">chart</primary><relation line=\"1\""
+ + "><call line=\"1\"><primary line=\"1\""
+ + ">getItemAt</primary><arguments line=\"1\"" + "><primary line=\"1\""
+ + ">0</primary></arguments><array line=\"1\"" + "><primary line=\"1\""
+ + ">xField</primary></array></call><op line=\"1\"" + ">></op><primary "
+ + "line=\"1\">targetXFieldValue</primary>"
+ + "</relation></dot></condition><block line=\"1\"" + "></block></if>");
+ }
+
+ @Test
+ public void testIfWithEmptyStatement() throws TokenException {
+ assertStatement("1",
+ "if( i++ ); ",
+ "<if line=\"1\"><condition line=\"1\">"
+ + "<post-inc line=\"1\"><primary line=\"1\">"
+ + "i</primary></post-inc></condition><stmt-empty line=\"1\">;"
+ + "</stmt-empty></if>");
+ }
+
+ @Test
+ public void testIfWithoutBlock() throws TokenException {
+ assertStatement("1",
+ "if( i++ ) trace( i ); ",
+ "<if line=\"1\"><condition line=\"1\">"
+ + "<post-inc line=\"1\"><primary line=\"1\">i"
+ + "</primary></post-inc></condition><call line=\"1\">"
+ + "<primary line=\"1\">trace</primary><arguments line=\"1\""
+ + "><primary line=\"1\">i</primary>" + "</arguments></call></if>");
+ }
+
+ @Test
+ public void testIfWithReturn() throws TokenException {
+ assertStatement("",
+ "if ( true )return;",
+ "<if line=\"1\"><condition line=\"1\"><primary line=\"1\""
+ + ">true</primary></condition><return line=\"2\"" + "></return></if>");
+
+ assertStatement("",
+ "if ( true )throw new Error();",
+ "<if line=\"1\"><condition line=\"1\"><primary line=\"1\""
+ + ">true</primary></condition><primary line=\"1\">" + "throw</primary></if>");
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestInterface.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestInterface.java b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestInterface.java
new file mode 100644
index 0000000..cf27b05
--- /dev/null
+++ b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestInterface.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.flex.pmd.parser.impl;
+
+import static org.testng.Assert.*;
+
+import org.apache.flex.pmd.parser.exceptions.TokenException;
+import org.testng.annotations.Test;
+
+public class TestInterface extends AbstractAs3ParserTestBase {
+
+ @Test
+ public void testExtends() throws TokenException {
+ assertPackageContent("1",
+ "public interface A extends B { } ",
+ "<content line=\"2\"><interface line=\"2\">"
+ + "<name line=\"2\">A</name><mod-list line=\"2\">"
+ + "<mod line=\"2\">public</mod>"
+ + "</mod-list><extends line=\"2\">B</extends>"
+ + "<content line=\"2\"></content></interface></content>");
+
+ assertPackageContent("",
+ " public interface ITimelineEntryRenderer extends IFlexDisplayObject, IDataRenderer{}",
+ "<content line=\"2\"><interface line=\"2\"><name line=\"2\""
+ + ">ITimelineEntryRenderer</name><mod-list line=\"2\">"
+ + "<mod line=\"2\">public</mod></mod-list><extends line=\"2\""
+ + ">IFlexDisplayObject</extends><extends line=\"2\">"
+ + "IDataRenderer</extends><content line=\"2\">"
+ + "</content></interface></content>");
+ }
+
+ @Test
+ public void testInclude() throws TokenException {
+ assertPackageContent("1",
+ "public interface A extends B { include \"ITextFieldInterface.asz\" } ",
+ "<content line=\"2\"><interface line=\"2\">"
+ + "<name line=\"2\">A</name><mod-list line=\"2\">"
+ + "<mod line=\"2\">public</mod></mod-list>" + "<extends line=\"2\">"
+ + "B</extends><content line=\"2\"><include line=\"2\">"
+ + "<primary line=\"2\">\"ITextFieldInterface.asz\"</primary>"
+ + "</include></content></interface></content>");
+ }
+
+ private void assertPackageContent(final String message,
+ final String input,
+ final String expected) throws TokenException {
+ scn.setLines(new String[]
+ {"{",
+ input,
+ "}",
+ "__END__"});
+ asp.nextToken(); // first call
+ asp.nextToken(); // skip {
+ final String result = new ASTToXMLConverter().convert(asp.parsePackageContent());
+ assertEquals(expected, result, message);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestInterfaceContent.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestInterfaceContent.java b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestInterfaceContent.java
new file mode 100644
index 0000000..ea99d9b
--- /dev/null
+++ b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestInterfaceContent.java
@@ -0,0 +1,88 @@
+/*
+ * 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 org.apache.flex.pmd.parser.impl;
+
+import static org.testng.Assert.*;
+
+import org.apache.flex.pmd.parser.exceptions.TokenException;
+import org.testng.annotations.Test;
+
+public class TestInterfaceContent extends AbstractAs3ParserTestBase {
+
+ @Test
+ public void testConditionalCompilation() throws TokenException {
+ assertInterfaceContent("with conditional compilation",
+ "CONFIG::DEBUG { function output():String; } ",
+ "<function line=\"2\"><name line=\"2\">"
+ + "output</name><parameter-list line=\"2\"></parameter-list>"
+ + "<type line=\"2\">String</type></function>");
+ }
+
+ @Test
+ public void testImports() throws TokenException {
+ assertInterfaceContent("1",
+ "import a.b.c;",
+ "<import line=\"2\">a.b.c</import>");
+
+ assertInterfaceContent("2",
+ "import a.b.c import x.y.z",
+ "<import line=\"2\">a.b.c</import>"
+ + "<import line=\"2\">x.y.z</import>");
+ }
+
+ @Test
+ public void testMethods() throws TokenException {
+ assertInterfaceContent("1",
+ "function a()",
+ "<function line=\"3\">"
+ + "<name line=\"2\">a</name>"
+ + "<parameter-list line=\"2\">"
+ + "</parameter-list><type line=\"3\">"
+ + "</type></function>");
+
+ assertInterfaceContent("2",
+ "function set a( value : int ) : void",
+ "<set line=\"3\"><name line=\"2\">a"
+ + "</name><parameter-list line=\"2\">"
+ + "<parameter line=\"2\">"
+ + "<name-type-init line=\"2\">"
+ + "<name line=\"2\">value</name>"
+ + "<type line=\"2\">int</type>"
+ + "</name-type-init></parameter></parameter-list>"
+ + "<type line=\"2\">void</type></set>");
+
+ assertInterfaceContent("3",
+ "function get a() : int",
+ "<get line=\"3\"><name line=\"2\">a"
+ + "</name><parameter-list line=\"2\">"
+ + "</parameter-list><type line=\"2\">int" + "</type></get>");
+ }
+
+ private void assertInterfaceContent(final String message,
+ final String input,
+ final String expected) throws TokenException {
+ scn.setLines(new String[]
+ {"{",
+ input,
+ "}",
+ "__END__"});
+ asp.nextToken(); // first call
+ asp.nextToken(); // skip {
+ final String result = new ASTToXMLConverter().convert(asp.parseInterfaceContent());
+ assertEquals("<content line=\"2\">" + expected + "</content>", result, message);
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestPackageContent.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestPackageContent.java b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestPackageContent.java
new file mode 100644
index 0000000..224a0dd
--- /dev/null
+++ b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestPackageContent.java
@@ -0,0 +1,204 @@
+/*
+ * 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 org.apache.flex.pmd.parser.impl;
+
+import static org.testng.Assert.*;
+
+import org.apache.flex.pmd.parser.exceptions.TokenException;
+import org.testng.annotations.Test;
+
+public class TestPackageContent extends AbstractAs3ParserTestBase {
+
+ @Test
+ public void testClass() throws TokenException {
+ assertPackageContent("1",
+ "public class A { }",
+ "<content line=\"2\"><class line=\"2\">"
+ + "<name line=\"2\">A</name><mod-list line=\"2\">"
+ + "<mod line=\"2\">public</mod>" + "</mod-list><content line=\"2\">"
+ + "</content></class></content>");
+ }
+
+ @Test
+ public void testClassWithAsDoc() throws TokenException {
+ assertPackageContent("1",
+ "/** AsDoc */ public class A { }",
+ "<content line=\"2\"><class line=\"2\">"
+ + "<as-doc line=\"2\">/** AsDoc */</as-doc><name line=\"2\""
+ + ">A</name><mod-list line=\"2\"><mod line=\"2\""
+ + ">public</mod></mod-list><content line=\"2\">"
+ + "</content></class></content>");
+ }
+
+ @Test
+ public void testClassWithAsDocComplex() throws TokenException {
+ assertPackageContent("1",
+ "/** AsDoc */ public class A { "
+ + "/** Member */ " + "public var tmp : Number; "
+ + "private var tmp2 : int; " + "/** Function */ "
+ + "protected function foo() : void { } }",
+ "<content line=\"2\"><class line=\"2\"><as-doc line=\"2\""
+ + ">/** AsDoc */</as-doc><name line=\"2\">A</name>"
+ + "<mod-list line=\"2\"><mod line=\"2\">public</mod>"
+ + "</mod-list><content line=\"2\"><var-list line=\"2\">"
+ + "<mod-list line=\"2\"><mod line=\"2\">public</mod>"
+ + "</mod-list><name-type-init line=\"2\"><name line=\"2\">tmp</name>"
+ + "<type line=\"2\">Number</type></name-type-init><as-doc line=\"2\""
+ + ">/** Member */</as-doc></var-list><var-list line=\"2\">"
+ + "<mod-list line=\"2\"><mod line=\"2\">private</mod></mod-list>"
+ + "<name-type-init line=\"2\"><name line=\"2\">tmp2</name>"
+ + "<type line=\"2\">int</type></name-type-init></var-list><function "
+ + "line=\"2\"><as-doc line=\"2\">/** Function */</as-doc>"
+ + "<mod-list line=\"2\"><mod line=\"2\">protected</mod></mod-list>"
+ + "<name line=\"2\">foo</name><parameter-list line=\"2\">"
+ + "</parameter-list><type line=\"2\">void</type><block line=\"2\""
+ + "></block></function></content></class></content>");
+ }
+
+ @Test
+ public void testClassWithComment() throws TokenException {
+ assertPackageContent("1",
+ "/* lala */ /** asDoc */ public class A { }",
+ "<content line=\"2\"><class line=\"2\">"
+ + "<as-doc line=\"2\">/** asDoc */</as-doc><multi-line-comment "
+ + "line=\"2\">/* lala */</multi-line-comment><name line=\"2\""
+ + ">A</name><mod-list line=\"2\"><mod line=\"2\""
+ + ">public</mod></mod-list><content line=\"2\">"
+ + "</content></class></content>");
+ }
+
+ @Test
+ public void testClassWithMetadata() throws TokenException {
+ assertPackageContent("1",
+ "[Bindable(name=\"abc\", value=\"123\")] public class A { }",
+ "<content line=\"2\"><class line=\"2\">"
+ + "<name line=\"2\">A</name><meta-list line=\"2\">" + "<meta line=\"2\""
+ + ">Bindable ( name = \"abc\" , value = \"123\" )</meta>"
+ + "</meta-list><mod-list line=\"2\">" + "<mod line=\"2\">public"
+ + "</mod></mod-list><content line=\"2\"></content></class></content>");
+ }
+
+ @Test
+ public void testClassWithMetadataAsDoc() throws TokenException {
+ assertPackageContent("1",
+ "/** Comment */ [Bindable] public class A { }",
+ "<content line=\"2\"><class line=\"2\"><as-doc line=\"2\">"
+ + "/** Comment */</as-doc><name line=\"2\">A</name><meta-list "
+ + "line=\"2\"><meta line=\"2\">Bindable</meta></meta-list><mod-list "
+ + "line=\"2\"><mod line=\"2\">public</mod></mod-list><content "
+ + "line=\"2\"></content></class></content>");
+ }
+
+ @Test
+ public void testClassWithMetadataComment() throws TokenException {
+ assertPackageContent("1",
+ "/* Comment */ [Bindable] public class A { }",
+ "<content line=\"2\"><class line=\"2\">"
+ + "<multi-line-comment line=\"2\">/* Comment */"
+ + "</multi-line-comment><name line=\"2\">A</name>"
+ + "<meta-list line=\"2\"><meta line=\"2\">"
+ + "Bindable</meta></meta-list><mod-list line=\"2\"><mod "
+ + "line=\"2\">public</mod></mod-list><content line=\"2\""
+ + "></content></class></content>");
+ }
+
+ @Test
+ public void testClassWithMetadataWithComment() throws TokenException {
+ assertPackageContent("1",
+ "/* lala */ /** asDoc */ [Bindable] public class A { }",
+ "<content line=\"2\"><class line=\"2\"><as-doc line=\"2\">"
+ + "/** asDoc */</as-doc><multi-line-comment line=\"2\">"
+ + "/* lala */</multi-line-comment><name line=\"2\">A</name>"
+ + "<meta-list line=\"2\"><meta line=\"2\">Bindable</meta>"
+ + "</meta-list><mod-list line=\"2\"><mod line=\"2\">public"
+ + "</mod></mod-list><content line=\"2\"></content></class></content>");
+ }
+
+ @Test
+ public void testClassWithSimpleMetadata() throws TokenException {
+ assertPackageContent("1",
+ "[Bindable] public class A { }",
+ "<content line=\"2\"><class line=\"2\"><name line=\"2\""
+ + ">A</name><meta-list line=\"2\"><meta line=\"2\""
+ + ">Bindable</meta></meta-list><mod-list line=\"2\">"
+ + "<mod line=\"2\">public</mod></mod-list><content line=\"2\""
+ + "></content></class></content>");
+ }
+
+ @Test
+ public void testImports() throws TokenException {
+ assertPackageContent("1",
+ "import a.b.c;",
+ "<content line=\"2\"><import line=\"2\""
+ + ">a.b.c</import></content>");
+
+ assertPackageContent("2",
+ "import a.b.c import x.y.z",
+ "<content line=\"2\"><import line=\"2\">a.b.c"
+ + "</import><import line=\"2\">x.y.z</import></content>");
+ }
+
+ @Test
+ public void testInterface() throws TokenException {
+ assertPackageContent("1",
+ "public interface A { }",
+ "<content line=\"2\"><interface line=\"2\">"
+ + "<name line=\"2\">A</name><mod-list line=\"2\">"
+ + "<mod line=\"2\">public</mod>" + "</mod-list><content line=\"2\">"
+ + "</content></interface></content>");
+ }
+
+ @Test
+ public void testMethodPackages() throws TokenException {
+ assertPackageContent("1",
+ "public function a() : void { }",
+ "<content line=\"2\"><function line=\"2\">"
+ + "<mod-list line=\"2\"><mod line=\"2\">public</mod>"
+ + "</mod-list><name line=\"2\">a</name><parameter-list line=\"2\""
+ + "></parameter-list><type line=\"2\">void</type>"
+ + "<block line=\"2\"></block></function></content>");
+ }
+
+ @Test
+ public void testUse() throws TokenException {
+ assertPackageContent("1",
+ "use namespace myNamespace",
+ "<content line=\"2\"><use line=\"2\""
+ + ">myNamespace</use></content>");
+ }
+
+ @Test
+ public void testUseNameSpace() throws TokenException {
+ assertPackageContent("FlexPMD-108",
+ "use namespace mx_internal;",
+ "<content line=\"2\"><use line=\"2\">mx_internal</use></content>");
+ }
+
+ private void assertPackageContent(final String message,
+ final String input,
+ final String expected) throws TokenException {
+ scn.setLines(new String[]
+ {"{",
+ input,
+ "}",
+ "__END__"});
+ asp.nextToken(); // first call
+ asp.nextToken(); // skip {
+ final String result = new ASTToXMLConverter().convert(asp.parsePackageContent());
+ assertEquals(expected, result, message);
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestPrimaryExpression.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestPrimaryExpression.java b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestPrimaryExpression.java
new file mode 100644
index 0000000..81a8730
--- /dev/null
+++ b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestPrimaryExpression.java
@@ -0,0 +1,102 @@
+/*
+ * 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 org.apache.flex.pmd.parser.impl;
+
+import static org.testng.Assert.*;
+
+import org.apache.flex.pmd.parser.exceptions.TokenException;
+import org.testng.annotations.Test;
+
+public class TestPrimaryExpression extends AbstractAs3ParserTestBase {
+
+ @Test
+ public void testArrayLiteral() throws TokenException {
+ assertPrimary("[1,2,3]",
+ "<array line=\"1\"><primary line=\"1\">1"
+ + "</primary><primary line=\"1\">2</primary>"
+ + "<primary line=\"1\">3</primary></array>");
+ }
+
+ @Test
+ public void testBooleans() throws TokenException {
+ assertPrimary("true");
+ assertPrimary("false");
+ }
+
+ @Test
+ public void testFunctionLiteral() throws TokenException {
+ assertPrimary("function ( a : Object ) : * { trace('test'); }",
+ "<lambda line=\"1\"><parameter-list line=\"1\">"
+ + "<parameter line=\"1\"><name-type-init line=\"1\">"
+ + "<name line=\"1\">a</name><type line=\"1\">"
+ + "Object</type></name-type-init></parameter></parameter-list>"
+ + "<type line=\"1\">*</type><block line=\"1\">"
+ + "<call line=\"1\"><primary line=\"1\">trace</primary>"
+ + "<arguments line=\"1\"><primary line=\"1\">'test'"
+ + "</primary></arguments></call></block></lambda>");
+ }
+
+ @Test
+ public void testNull() throws TokenException {
+ assertPrimary("null");
+ }
+
+ @Test
+ public void testNumbers() throws TokenException {
+ assertPrimary("1");
+ assertPrimary("0xff");
+ assertPrimary("0777");
+ assertPrimary(".12E5");
+ }
+
+ @Test
+ public void testObjectLiteral() throws TokenException {
+ assertPrimary("{a:1,b:2}",
+ "<object line=\"1\"><prop line=\"1\">"
+ + "<name line=\"1\">a</name><value line=\"1\">"
+ + "<primary line=\"1\">1</primary></value></prop><prop line=\"1\">"
+ + "<name line=\"1\">b</name><value line=\"1\">"
+ + "<primary line=\"1\">2</primary></value></prop></object>");
+ }
+
+ @Test
+ public void testStrings() throws TokenException {
+ assertPrimary("\"string\"");
+ assertPrimary("'string'");
+ }
+
+ @Test
+ public void testUndefined() throws TokenException {
+ assertPrimary("undefined");
+ }
+
+ private void assertPrimary(final String input) throws TokenException {
+ assertPrimary(input,
+ input);
+ }
+
+ private void assertPrimary(final String input,
+ final String expected) throws TokenException {
+ scn.setLines(new String[]
+ {input,
+ "__END__"});
+ asp.nextToken();
+ final String result = new ASTToXMLConverter().convert(asp.parsePrimaryExpression());
+ assertEquals("<primary line=\"1\">" + expected + "</primary>", result, "unexpected");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestReturnStatement.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestReturnStatement.java b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestReturnStatement.java
new file mode 100644
index 0000000..8110a05
--- /dev/null
+++ b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestReturnStatement.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.flex.pmd.parser.impl;
+
+import org.apache.flex.pmd.parser.exceptions.TokenException;
+import org.testng.annotations.Test;
+
+public class TestReturnStatement extends AbstractStatementTestBase {
+
+ @Test
+ public void testEmptyReturn() throws TokenException {
+ assertStatement("1",
+ "return",
+ "<return line=\"2\"></return>");
+
+ assertStatement("2",
+ "return;",
+ "<return line=\"2\"></return>");
+ }
+
+ @Test
+ public void testFlexPMD181a() throws TokenException {
+ assertStatement("1",
+ "return (str1 === str2);",
+ "<return line=\"1\"><primary line=\"1\"><encapsulated line=\"1\">"
+ + "<equality line=\"1\"><primary line=\"1\">str1</primary><op line=\"1\">"
+ + "===</op><primary line=\"1\">str2</primary></equality>"
+ + "</encapsulated></primary></return>");
+ }
+
+ @Test
+ public void testFlexPMD181b() throws TokenException {
+ assertStatement("1",
+ "return testString(str, /^[a-zA-Z\\s]*$/);",
+ "<return line=\"1\"><call line=\"1\"><primary line=\"1\">testString"
+ + "</primary><arguments line=\"1\"><primary line=\"1\">str</primary>"
+ + "<primary line=\"1\">/^[a-zA-Z\\s]*$/</primary></arguments></call></return>");
+ }
+
+ @Test
+ public void testReturnArrayLiteral() throws TokenException {
+ assertStatement("1",
+ "return []",
+ "<return line=\"1\"><primary line=\"1\">"
+ + "<array line=\"1\"></array></primary></return>");
+ assertStatement("2",
+ "return [];",
+ "<return line=\"1\"><primary line=\"1\">"
+ + "<array line=\"1\"></array></primary></return>");
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestSwitchStatement.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestSwitchStatement.java b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestSwitchStatement.java
new file mode 100644
index 0000000..284cc6b
--- /dev/null
+++ b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestSwitchStatement.java
@@ -0,0 +1,50 @@
+/*
+ * 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 org.apache.flex.pmd.parser.impl;
+
+import org.apache.flex.pmd.parser.exceptions.TokenException;
+import org.testng.annotations.Test;
+
+public class TestSwitchStatement extends AbstractStatementTestBase {
+
+ @Test
+ public void testFullFeatured() throws TokenException {
+ assertStatement("1",
+ "switch( x ){ case 1 : trace('one'); break; default : trace('unknown'); }",
+ "<switch line=\"1\"><condition line=\"1\">"
+ + "<primary line=\"1\">x</primary>" + "</condition><cases line=\"1\">"
+ + "<case line=\"1\"><primary line=\"1\">1</primary>"
+ + "<switch-block line=\"1\"><call line=\"1\">"
+ + "<primary line=\"1\">trace</primary><arguments line=\"1\">"
+ + "<primary line=\"1\">'one'</primary></arguments>"
+ + "</call><primary line=\"1\">break</primary>"
+ + "</switch-block></case><case line=\"1\">" + "<default line=\"1\">"
+ + "default</default><switch-block line=\"1\">"
+ + "<call line=\"1\"><primary line=\"1\">trace" + "</primary>"
+ + "<arguments line=\"1\">" + "<primary line=\"1\">'unknown'</primary>"
+ + "</arguments></call></switch-block></case></cases></switch>");
+ assertStatement("1",
+ "switch( x ){ case 1 : break; default:}",
+ "<switch line=\"1\"><condition line=\"1\"><primary line=\"1\""
+ + ">x</primary></condition><cases line=\"1\"><case line=\"1\""
+ + "><primary line=\"1\">1</primary><switch-block line=\"1\""
+ + "><primary line=\"1\">break</primary></switch-block></case>"
+ + "<case line=\"1\"><default line=\"1\">default</default>"
+ + "<switch-block line=\"1\"></switch-block></case></cases></switch>");
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestTryCatchFinallyStatement.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestTryCatchFinallyStatement.java b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestTryCatchFinallyStatement.java
new file mode 100644
index 0000000..190f129
--- /dev/null
+++ b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestTryCatchFinallyStatement.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.flex.pmd.parser.impl;
+
+import org.apache.flex.pmd.parser.exceptions.TokenException;
+import org.testng.annotations.Test;
+
+public class TestTryCatchFinallyStatement extends AbstractStatementTestBase {
+
+ @Test
+ public void testCatch() throws TokenException {
+ assertStatement("1",
+ "catch( e : Error ) {trace( true ); }",
+ "<catch line=\"1\"><name line=\"1\">e"
+ + "</name><type line=\"1\">Error</type><block line=\"1\">"
+ + "<call line=\"1\"><primary line=\"1\">trace</primary>"
+ + "<arguments line=\"1\"><primary line=\"1\">true"
+ + "</primary></arguments></call></block></catch>");
+ }
+
+ @Test
+ public void testFinally() throws TokenException {
+ assertStatement("1",
+ "finally {trace( true ); }",
+ "<finally line=\"1\"><block line=\"1\">"
+ + "<call line=\"1\"><primary line=\"1\">"
+ + "trace</primary><arguments line=\"1\"><primary line=\"1\">"
+ + "true</primary></arguments></call></block></finally>");
+ }
+
+ @Test
+ public void testTry() throws TokenException {
+ assertStatement("1",
+ "try {trace( true ); }",
+ "<try line=\"1\"><block line=\"1\">"
+ + "<call line=\"1\"><primary line=\"1\">"
+ + "trace</primary><arguments line=\"1\"><primary line=\"1\">"
+ + "true</primary></arguments></call></block></try>");
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestUnaryExpression.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestUnaryExpression.java b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestUnaryExpression.java
new file mode 100644
index 0000000..5cc2b01
--- /dev/null
+++ b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestUnaryExpression.java
@@ -0,0 +1,126 @@
+/*
+ * 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 org.apache.flex.pmd.parser.impl;
+
+import org.apache.flex.pmd.parser.exceptions.TokenException;
+import org.testng.annotations.Test;
+
+public class TestUnaryExpression extends AbstractStatementTestBase {
+
+ @Test
+ public void testArrayAccess() throws TokenException {
+ assertStatement("1",
+ "x[0]",
+ "<arr-acc line=\"1\"><primary line=\"1\">x<"
+ + "/primary><primary line=\"1\">0</primary></arr-acc>");
+ }
+
+ @Test
+ public void testComplex() throws TokenException {
+ assertStatement("1",
+ "a.b['c'].d.e(1)",
+ "<dot line=\"1\"><primary line=\"1\">a"
+ + "</primary><dot line=\"1\"><arr-acc line=\"1\">"
+ + "<primary line=\"1\">b</primary><primary line=\"1\">"
+ + "'c'</primary></arr-acc><dot line=\"1\"><primary line=\"1\">"
+ + "d</primary><call line=\"1\"><primary line=\"1\">e"
+ + "</primary><arguments line=\"1\"><primary line=\"1\">1"
+ + "</primary></arguments></call></dot></dot></dot>");
+
+ assertStatement("2",
+ "a.b['c']['d'].e(1)",
+ "<dot line=\"1\"><primary line=\"1\">a"
+ + "</primary><dot line=\"1\"><arr-acc line=\"1\">"
+ + "<primary line=\"1\">b</primary><primary line=\"1\">"
+ + "'c'</primary><primary line=\"1\">'d'</primary>"
+ + "</arr-acc><call line=\"1\"><primary line=\"1\">"
+ + "e</primary><arguments line=\"1\"><primary line=\"1\">1"
+ + "</primary></arguments></call></dot></dot>");
+ }
+
+ @Test
+ public void testMethodCall() throws TokenException {
+ assertStatement("1",
+ "method()",
+ "<call line=\"1\"><primary line=\"1\">"
+ + "method</primary><arguments line=\"1\"></arguments></call>");
+
+ assertStatement("2",
+ "method( 1, \"two\" )",
+ "<call line=\"1\"><primary line=\"1\">"
+ + "method</primary><arguments line=\"1\"><primary line=\"1\">1"
+ + "</primary><primary line=\"1\">\"two\"</primary></arguments></call>");
+ }
+
+ @Test
+ public void testMultipleMethodCall() throws TokenException {
+ assertStatement("1",
+ "method()()",
+ "<call line=\"1\"><primary line=\"1\">"
+ + "method</primary><arguments line=\"1\"></arguments>"
+ + "<arguments line=\"1\"></arguments></call>");
+ }
+
+ @Test
+ public void testParseUnaryExpressions() throws TokenException {
+ assertStatement("1",
+ "++x",
+ "<pre-inc line=\"1\"><primary line=\"1\">x</primary></pre-inc>");
+ assertStatement("2",
+ "x++",
+ "<post-inc line=\"2\"><primary line=\"1\">x</primary></post-inc>");
+ assertStatement("3",
+ "--x",
+ "<pre-dec line=\"1\"><primary line=\"1\">x</primary></pre-dec>");
+ assertStatement("4",
+ "x--",
+ "<post-dec line=\"2\"><primary line=\"1\">x</primary></post-dec>");
+ assertStatement("5",
+ "+x",
+ "<plus line=\"1\"><primary line=\"1\">x</primary></plus>");
+ assertStatement("6",
+ "+ x",
+ "<plus line=\"1\"><primary line=\"1\">x</primary></plus>");
+ assertStatement("7",
+ "-x",
+ "<minus line=\"1\"><primary line=\"1\">x</primary></minus>");
+ assertStatement("8",
+ "- x",
+ "<minus line=\"1\"><primary line=\"1\">x</primary></minus>");
+ assertStatement("9",
+ "delete x",
+ "<delete line=\"1\"><primary line=\"1\">x</primary></delete>");
+ assertStatement("a",
+ "void x",
+ "<void line=\"1\"><primary line=\"1\">x</primary></void>");
+ assertStatement("b",
+ "typeof x",
+ "<typeof line=\"1\"><primary line=\"1\">x</primary></typeof>");
+ assertStatement("c",
+ "! x",
+ "<not line=\"1\"><primary line=\"1\">x</primary></not>");
+ assertStatement("d",
+ "~ x",
+ "<b-not line=\"1\"><primary line=\"1\">x</primary></b-not>");
+ assertStatement("e",
+ "x++",
+ "<post-inc line=\"2\"><primary line=\"1\">x</primary></post-inc>");
+ assertStatement("f",
+ "x--",
+ "<post-dec line=\"2\"><primary line=\"1\">x</primary></post-dec>");
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestVarStatement.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestVarStatement.java b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestVarStatement.java
new file mode 100644
index 0000000..325ed06
--- /dev/null
+++ b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestVarStatement.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 org.apache.flex.pmd.parser.impl;
+
+import org.apache.flex.pmd.parser.exceptions.TokenException;
+import org.testng.annotations.Test;
+
+public class TestVarStatement extends AbstractStatementTestBase {
+
+ @Test
+ public void testFlexPMD211() throws TokenException {
+ assertStatement("",
+ "var a:Vector.<String> = new Vector.<String>();\nvar i:int;",
+ "<var-list line=\"1\"><name-type-init line=\"1\"><name line=\"1\">a</name>"
+ + "<vector line=\"1\"><type line=\"1\">String</type></vector>"
+ + "<init line=\"1\"><new line=\"1\"><primary line=\"1\">Vector</primary>"
+ + "<vector line=\"1\"><vector line=\"1\"><type line=\"1\">String</type>"
+ + "</vector></vector><arguments line=\"1\"></arguments></new></init>"
+ + "</name-type-init></var-list>");
+ }
+
+ @Test
+ public void testFullFeaturedVar() throws TokenException {
+ assertStatement("1",
+ "var a : int = 4",
+ "<var-list line=\"1\">"
+ + "<name-type-init line=\"1\">"
+ + "<name line=\"1\">a</name><type line=\"1\">int</type>"
+ + "<init line=\"1\"><primary line=\"1\">4</primary>"
+ + "</init></name-type-init></var-list>");
+
+ assertStatement("1",
+ "var a : int = 4, b : int = 2;",
+ "<var-list line=\"1\"><name-type-init line=\"1\">"
+ + "<name line=\"1\">a</name><type line=\"1\">int</type>"
+ + "<init line=\"1\"><primary line=\"1\">4</primary></init>"
+ + "</name-type-init><name-type-init line=\"1\">"
+ + "<name line=\"1\">b</name><type line=\"1\">int</type>"
+ + "<init line=\"1\"><primary line=\"1\">2</primary></init>"
+ + "</name-type-init></var-list>");
+
+ assertStatement("with array",
+ "var colors:Array = [0x2bc9f6, 0x0086ad];",
+ "<var-list line=\"1\">"
+ + "<name-type-init line=\"1\">"
+ + "<name line=\"1\">colors</name><type line=\"1\">Array</type>"
+ + "<init line=\"1\">" + "<primary line=\"1\"><array line=\"1\">"
+ + "<primary line=\"1\">0x2bc9f6</primary>"
+ + "<primary line=\"1\">0x0086ad</primary>"
+ + "</array></primary></init></name-type-init></var-list>");
+ }
+
+ @Test
+ public void testInitializedVar() throws TokenException {
+ assertStatement("1",
+ "var a = 4",
+ "<var-list line=\"1\"><name-type-init line=\"1\">"
+ + "<name line=\"1\">a</name><type line=\"1\">"
+ + "</type><init line=\"1\"><primary line=\"1\">4</primary>"
+ + "</init></name-type-init></var-list>");
+ }
+
+ @Test
+ public void testSimpleVar() throws TokenException {
+ assertStatement("1",
+ "var a",
+ "<var-list line=\"1\"><name-type-init line=\"1\">"
+ + "<name line=\"1\">a</name><type line=\"2\">"
+ + "</type></name-type-init></var-list>");
+ }
+
+ @Test
+ public void testTypedVar() throws TokenException {
+ assertStatement("1",
+ "var a : Object",
+ "<var-list line=\"1\"><name-type-init line=\"1\">"
+ + "<name line=\"1\">a</name><type line=\"1\">Object</type>"
+ + "</name-type-init></var-list>");
+ }
+
+ @Test
+ public void testVector() throws TokenException {
+ assertStatement("vector",
+ "var v:Vector.<DisplayObject> = new Vector.<Sprite>();",
+ "<var-list line=\"1\"><name-type-init line=\"1\"><name line=\"1\">v</name><vector line=\"1\"><type line=\"1\">DisplayObject</type></vector><init line=\"1\"><new line=\"1\"><primary line=\"1\">Vector</primary><vector line=\"1\"><vector line=\"1\"><type line=\"1\">Sprite</type></vector></vector><arguments line=\"1\"></arguments></new></init></name-type-init></var-list>");
+
+ assertStatement("vector",
+ "var v:Vector.< Vector.< String > >",
+ "<var-list line=\"1\"><name-type-init line=\"1\">"
+ + "<name line=\"1\">" + "v</name><vector line=\"1\"><vector line=\"1\""
+ + "><type line=\"1\""
+ + ">String</type></vector></vector></name-type-init></var-list>");
+
+ assertStatement("vector",
+ "var v:Vector.<Vector.<String>>;",
+ "<var-list line=\"1\"><name-type-init line=\"1\">"
+ + "<name line=\"1\">"
+ + "v</name><vector line=\"1\"><vector line=\"1\"><type line=\"1\""
+ + ">String</type></vector></vector></name-type-init></var-list>");
+
+ assertStatement("",
+ "var HT:Vector.<BitString> = new Vector.<BitString>(251, true);",
+ "<var-list line=\"1\"><name-type-init line=\"1\"><name line=\"1\">HT</name><vector line=\"1\"><type line=\"1\">BitString</type></vector><init line=\"1\"><new line=\"1\"><primary line=\"1\">Vector</primary><vector line=\"1\"><vector line=\"1\"><type line=\"1\">BitString</type></vector></vector><arguments line=\"1\"><primary line=\"1\">251</primary><primary line=\"1\">true</primary></arguments></new></init></name-type-init></var-list>");
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestWhileStatement.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestWhileStatement.java b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestWhileStatement.java
new file mode 100644
index 0000000..6cd12dc
--- /dev/null
+++ b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestWhileStatement.java
@@ -0,0 +1,63 @@
+/*
+ * 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 org.apache.flex.pmd.parser.impl;
+
+import org.apache.flex.pmd.parser.exceptions.TokenException;
+import org.testng.annotations.Test;
+
+public class TestWhileStatement extends AbstractStatementTestBase {
+
+ @Test
+ public void testWhile() throws TokenException {
+ assertStatement("1",
+ "while( i++ ){ trace( i ); }",
+ "<while line=\"1\">"
+ + "<condition line=\"1\">"
+ + "<post-inc line=\"1\">"
+ + "<primary line=\"1\">i</primary>"
+ + "</post-inc>"
+ + "</condition>"
+ + "<block line=\"1\"><call line=\"1\">"
+ + "<primary line=\"1\">trace</primary>"
+ + "<arguments line=\"1\"><primary line=\"1\">i</primary>"
+ + "</arguments></call>" + "</block>" + "</while>");
+ }
+
+ @Test
+ public void testWhileWithEmptyStatement() throws TokenException {
+ assertStatement("1",
+ "while( i++ ); ",
+ "<while line=\"1\">"
+ + "<condition line=\"1\">"
+ + "<post-inc line=\"1\">"
+ + "<primary line=\"1\">i</primary>"
+ + "</post-inc></condition><stmt-empty line=\"1\">;</stmt-empty></while>");
+ }
+
+ @Test
+ public void testWhileWithoutBlock() throws TokenException {
+ assertStatement("1",
+ "while( i++ ) trace( i ); ",
+ "<while line=\"1\">"
+ + "<condition line=\"1\">"
+ + "<post-inc line=\"1\">"
+ + "<primary line=\"1\">i</primary>"
+ + "</post-inc></condition><call line=\"1\">"
+ + "<primary line=\"1\">trace</primary><arguments line=\"1\">"
+ + "<primary line=\"1\">i</primary></arguments></call></while>");
+ }
+}
[16/24] git commit: [flex-utilities]
[refs/heads/feature/pmd-5.2-language-module] - Initial commit of the PMD
language module for Apache Flex
Posted by cd...@apache.org.
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/AbstractPrimaryAstRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/AbstractPrimaryAstRule.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/AbstractPrimaryAstRule.java
new file mode 100644
index 0000000..8deff1f
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/AbstractPrimaryAstRule.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 org.apache.flex.pmd.rules.core;
+
+import org.apache.flex.pmd.nodes.IFunction;
+import org.apache.flex.pmd.parser.IParserNode;
+
+import java.util.List;
+
+/**
+ * Abstract rule which find a primary (or a couple of primaries) in a body
+ * function.
+ *
+ * @author xagnetti
+ */
+public abstract class AbstractPrimaryAstRule extends AbstractAstFlexRule {
+ /**
+ * @param statement
+ * @param function
+ */
+ protected abstract void addViolation(IParserNode statement,
+ IFunction function);
+
+ /*
+ * (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 List<IParserNode> firstStatements = function.findPrimaryStatementsInBody(getFirstPrimaryToFind());
+ if (!firstStatements.isEmpty()) {
+ for (final IParserNode firstStatement : firstStatements) {
+ if (getSecondPrimaryToFind() == null) {
+ addViolation(firstStatement,
+ function);
+ } else {
+ final List<IParserNode> secondStatements = function.findPrimaryStatementsInBody(getSecondPrimaryToFind());
+ if (!secondStatements.isEmpty()) {
+ for (final IParserNode secondStatement : secondStatements) {
+ addViolation(secondStatement,
+ function);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * @return
+ */
+ protected abstract String getFirstPrimaryToFind();
+
+ /**
+ * @return
+ */
+ protected String getSecondPrimaryToFind() {
+ return null;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/AbstractRegexpBasedRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/AbstractRegexpBasedRule.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/AbstractRegexpBasedRule.java
new file mode 100644
index 0000000..3d13afd
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/AbstractRegexpBasedRule.java
@@ -0,0 +1,106 @@
+/*
+ * 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 org.apache.flex.pmd.rules.core;
+
+import org.apache.flex.pmd.rules.IFlexViolation;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * @author xagnetti
+ */
+public abstract class AbstractRegexpBasedRule extends AbstractFlexRule {
+ private Pattern pattern;
+
+ /**
+ *
+ */
+ public AbstractRegexpBasedRule() {
+ super();
+ compilePattern();
+ }
+
+ /**
+ *
+ */
+ public final void compilePattern() {
+ pattern = Pattern.compile(getRegexp());
+ }
+
+ /*
+ * (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 ("".compareTo(getRegexp()) != 0) {
+ for (int i = 1; i <= getCurrentFile().getLinesNb(); i++) {
+ final String line = getCurrentFile().getLineAt(i);
+
+ if (isCurrentLineConcerned(line)
+ && doesCurrentLineMacthes(line) && isViolationDetectedOnThisMatchingLine(line)
+ && !line.contains("/*") && !line.contains("//")) {
+ addViolation(violations,
+ ViolationPosition.create(i,
+ i,
+ 0,
+ line.length()));
+ }
+ }
+ }
+ return violations;
+ }
+
+ /**
+ * @param line
+ * @return
+ */
+ public boolean doesCurrentLineMacthes(final String line) {
+ return getMatcher(line).matches();
+ }
+
+ /**
+ * @param line
+ * @return
+ */
+ protected final Matcher getMatcher(final String line) {
+ final Matcher matcher = pattern.matcher(line);
+
+ return matcher;
+ }
+
+ /**
+ * @return
+ */
+ protected abstract String getRegexp();
+
+ protected boolean isCurrentLineConcerned(final String line) {
+ return true;
+ }
+
+ /**
+ * @param line
+ * @return
+ */
+ protected abstract boolean isViolationDetectedOnThisMatchingLine(final String line);
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/AbstractXpathRelatedRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/AbstractXpathRelatedRule.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/AbstractXpathRelatedRule.java
new file mode 100644
index 0000000..be76a3d
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/AbstractXpathRelatedRule.java
@@ -0,0 +1,211 @@
+/*
+ * 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 org.apache.flex.pmd.rules.core;
+
+import org.apache.flex.pmd.rules.IFlexViolation;
+import org.apache.flex.pmd.utils.StackTraceUtils;
+import org.w3c.dom.Document;
+import org.xml.sax.SAXException;
+
+import javax.xml.XMLConstants;
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathExpressionException;
+import javax.xml.xpath.XPathFactory;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.*;
+import java.util.logging.Logger;
+
+/**
+ * @author xagnetti
+ */
+public abstract class AbstractXpathRelatedRule extends AbstractFlexRule {
+ /**
+ * @author xagnetti
+ */
+ public class NamespaceContextMap implements NamespaceContext {
+ private final Map<String, String> prefixMap;
+
+ /**
+ * Constructor that takes a map of XML prefix-namespaceURI values. A
+ * defensive copy is made of the map. An IllegalArgumentException will be
+ * thrown if the map attempts to remap the standard prefixes defined in
+ * the NamespaceContext contract.
+ *
+ * @param prefixMappings a map of prefix:namespaceURI values
+ */
+ public NamespaceContextMap(final Map<String, String> prefixMappings) {
+ prefixMap = createPrefixMap(prefixMappings);
+ }
+
+ /**
+ * Convenience constructor.
+ *
+ * @param mappingPairs pairs of prefix-namespaceURI values
+ */
+ public NamespaceContextMap(final String... mappingPairs) {
+ this(toMap(mappingPairs));
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * javax.xml.namespace.NamespaceContext#getNamespaceURI(java.lang.String)
+ */
+ public String getNamespaceURI(final String prefix) {
+ prefixMap.get(prefix);
+ return prefixMap.get(prefix);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see javax.xml.namespace.NamespaceContext#getPrefix(java.lang.String)
+ */
+ public String getPrefix(final String namespaceURI) {
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see javax.xml.namespace.NamespaceContext#getPrefixes(java.lang.String)
+ */
+ public Iterator<String> getPrefixes(final String namespaceURI) {
+ return null;
+ }
+
+ private void addConstant(final Map<String, String> map,
+ final String prefix,
+ final String nsURI) {
+ map.put(prefix,
+ nsURI);
+ }
+
+ private Map<String, String> createPrefixMap(final Map<String, String> prefixMappings) {
+ final Map<String, String> map = new LinkedHashMap<String, String>(prefixMappings);
+ addConstant(map,
+ XMLConstants.XML_NS_PREFIX,
+ XMLConstants.XML_NS_URI);
+ addConstant(map,
+ XMLConstants.XMLNS_ATTRIBUTE,
+ XMLConstants.XMLNS_ATTRIBUTE_NS_URI);
+ return Collections.unmodifiableMap(map);
+ }
+
+ }
+
+ protected static final Logger LOGGER = Logger.getLogger(AbstractXpathRelatedRule.class.getName());
+
+ private static Map<String, String> toMap(final String... mappingPairs) {
+ final Map<String, String> prefixMappings = new LinkedHashMap<String, String>(mappingPairs.length / 2);
+ for (int i = 0; i < mappingPairs.length; i++) {
+ prefixMappings.put(mappingPairs[i],
+ mappingPairs[++i]);
+ }
+ return prefixMappings;
+ }
+
+ /**
+ * @param doc
+ * @param xPath
+ * @return
+ * @throws javax.xml.xpath.XPathExpressionException
+ */
+ protected abstract Object evaluate(final Document doc,
+ final XPath xPath) throws XPathExpressionException;
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractFlexRule#findViolationsInCurrentFile()
+ */
+ @Override
+ protected List<IFlexViolation> findViolationsInCurrentFile() {
+ final ArrayList<IFlexViolation> violations = new ArrayList<IFlexViolation>();
+
+ try {
+ final Document doc = buildDocument();
+ final XPath xPath = buildXPath();
+
+ onEvaluated(violations,
+ doc,
+ xPath);
+ } catch (final XPathExpressionException e) {
+ LOGGER.warning(StackTraceUtils.print(getCurrentFile().getFilename(),
+ e));
+ } catch (final FileNotFoundException e) {
+ LOGGER.warning(StackTraceUtils.print(getCurrentFile().getFilename(),
+ e));
+ } catch (final ParserConfigurationException e) {
+ LOGGER.warning(StackTraceUtils.print(getCurrentFile().getFilename(),
+ e));
+ } catch (final SAXException e) {
+ LOGGER.warning(StackTraceUtils.print(getCurrentFile().getFilename(),
+ e));
+ } catch (final IOException e) {
+ LOGGER.warning(StackTraceUtils.print(getCurrentFile().getFilename(),
+ e));
+ }
+
+ return violations;
+ }
+
+ /**
+ * @return
+ */
+ protected abstract String getXPathExpression();
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractFlexRule#isConcernedByTheCurrentFile()
+ */
+ @Override
+ protected boolean isConcernedByTheCurrentFile() {
+ return getCurrentFile().isMxml();
+ }
+
+ /**
+ * @param violations
+ * @param doc
+ * @param xPath
+ * @throws javax.xml.xpath.XPathExpressionException
+ */
+ protected abstract void onEvaluated(final List<IFlexViolation> violations,
+ final Document doc,
+ final XPath xPath) throws XPathExpressionException;
+
+ private Document buildDocument() throws ParserConfigurationException,
+ SAXException,
+ IOException {
+ final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ factory.setNamespaceAware(true);
+ final DocumentBuilder builder = factory.newDocumentBuilder();
+ return builder.parse(getCurrentFile().getFilePath());
+ }
+
+ private XPath buildXPath() {
+ final XPathFactory xPathFactory = XPathFactory.newInstance();
+ final XPath xPath = xPathFactory.newXPath();
+ xPath.setNamespaceContext(new NamespaceContextMap("mx", "http://www.adobe.com/2006/mxml"));
+ return xPath;
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/IFlexAstRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/IFlexAstRule.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/IFlexAstRule.java
new file mode 100644
index 0000000..774ddb9
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/IFlexAstRule.java
@@ -0,0 +1,27 @@
+/*
+ * 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 org.apache.flex.pmd.rules.core;
+
+/**
+ * @author xagnetti
+ */
+public interface IFlexAstRule extends IFlexRule {
+ /**
+ * @return true if the current file is concerned
+ */
+ boolean isConcernedByTheCurrentFile();
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/IFlexRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/IFlexRule.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/IFlexRule.java
new file mode 100644
index 0000000..a0b2ea5
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/IFlexRule.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 org.apache.flex.pmd.rules.core;
+
+import net.sourceforge.pmd.Rule;
+import org.apache.flex.pmd.files.IFlexFile;
+import org.apache.flex.pmd.nodes.IPackage;
+import org.apache.flex.pmd.rules.IFlexViolation;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * @author xagnetti
+ */
+public interface IFlexRule extends Rule {
+ /**
+ * @return ruleName
+ */
+ String getRuleName();
+
+ /**
+ * @param file
+ * @param rootNode
+ * @param files
+ * @return
+ */
+ List<IFlexViolation> processFile(final IFlexFile file,
+ final IPackage rootNode,
+ final Map<String, IFlexFile> files);
+
+ /**
+ * @param excludes
+ */
+ void setExcludes(final Set<String> excludes);
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/Violation.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/Violation.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/Violation.java
new file mode 100644
index 0000000..e7d0c79
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/Violation.java
@@ -0,0 +1,284 @@
+/*
+ * 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 org.apache.flex.pmd.rules.core;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.flex.pmd.files.IFlexFile;
+import org.apache.flex.pmd.rules.IFlexViolation;
+
+import java.util.Formatter;
+
+/**
+ * @author xagnetti
+ */
+public final class Violation implements IFlexViolation {
+ public static final String RULESET_CREATOR_URL = "http://opensource.adobe.com/svn/opensource/"
+ + "flexpmd/bin/flex-pmd-ruleset-creator.html?rule=";
+ private final int beginColumn;
+ private final int beginLine;
+ private int endColumn;
+ private final int endLine;
+ private final IFlexFile file;
+ private final IFlexRule rule;
+ private String ruleMessage = "";
+
+ /**
+ * @param position
+ * @param violatedRule
+ * @param violatedFile
+ */
+ public Violation(final ViolationPosition position,
+ final IFlexRule violatedRule,
+ final IFlexFile violatedFile) {
+ beginLine = position.getBeginLine();
+ endLine = position.getEndLine();
+ beginColumn = position.getBeginColumn();
+ endColumn = position.getEndColumn();
+ rule = violatedRule;
+ file = violatedFile;
+
+ if (violatedRule != null) {
+ ruleMessage = violatedRule.getMessage() == null ? ""
+ : violatedRule.getMessage();
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.IFlexViolation#appendToMessage(java.lang.String)
+ */
+ public void appendToMessage(final String messageToAppend) {
+ ruleMessage += messageToAppend;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.lang.Comparable#compareTo(java.lang.Object)
+ */
+ public int compareTo(final IFlexViolation otherViolation) // NO_UCD
+ {
+ int res;
+ final int priorityOrder = getPrioriyOrder(otherViolation);
+
+ if (priorityOrder == 0) {
+ res = getLinePriority(otherViolation);
+ } else {
+ res = priorityOrder;
+ }
+ return res;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see net.sourceforge.pmd.IRuleViolation#getBeginColumn()
+ */
+ public int getBeginColumn() {
+ return beginColumn;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see net.sourceforge.pmd.IRuleViolation#getBeginLine()
+ */
+ public int getBeginLine() {
+ return beginLine;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see net.sourceforge.pmd.IRuleViolation#getClassName()
+ */
+ public String getClassName() {
+ return "";
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see net.sourceforge.pmd.IRuleViolation#getDescription()
+ */
+ public String getDescription() {
+ return ruleMessage;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see net.sourceforge.pmd.IRuleViolation#getEndColumn()
+ */
+ public int getEndColumn() {
+ return endColumn;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see net.sourceforge.pmd.IRuleViolation#getEndLine()
+ */
+ public int getEndLine() {
+ return endLine;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see net.sourceforge.pmd.IRuleViolation#getFilename()
+ */
+ public String getFilename() {
+ return file.getFullyQualifiedName();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see net.sourceforge.pmd.IRuleViolation#getMethodName()
+ */
+ public String getMethodName() {
+ return "";
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see net.sourceforge.pmd.IRuleViolation#getPackageName()
+ */
+ public String getPackageName() {
+ return file.getPackageName();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see net.sourceforge.pmd.IRuleViolation#getRule()
+ */
+ public IFlexRule getRule() {
+ return rule;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.IFlexViolation#getRuleMessage()
+ */
+ public String getRuleMessage() {
+ return ruleMessage.endsWith(".") ? ruleMessage.substring(0,
+ ruleMessage.length() - 1)
+ : ruleMessage;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see net.sourceforge.pmd.IRuleViolation#getVariableName()
+ */
+ public String getVariableName() {
+ return "";
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see net.sourceforge.pmd.IRuleViolation#isSuppressed()
+ */
+ public boolean isSuppressed() {
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.IFlexViolation#replacePlaceholderInMessage(java.lang.
+ * String, int)
+ */
+ public void replacePlaceholderInMessage(final String replacement,
+ final int index) {
+ ruleMessage = ruleMessage.replace("{"
+ + index + "}",
+ replacement);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.IFlexViolation#setEndColumn(int)
+ */
+ public void setEndColumn(final int column) {
+ endColumn = column;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.IFlexViolation#toXmlString(com.adobe.ac.pmd.files.IFlexFile
+ * , java.lang.String)
+ */
+ public String toXmlString(final IFlexFile violatedFile,
+ final String ruleSetName) {
+ final Formatter formatter = new Formatter();
+
+ if (rule != null) {
+ final StringBuilder message = new StringBuilder(getRuleMessage());
+
+ formatter.format(" <violation beginline=\"%d\" "
+ + "endline=\"%d\" begincolumn=\"%d\" " + "endcolumn=\"%d\" rule=\"%s\" "
+ + "ruleset=\"%s\" package=\"%s\" " + "class=\"%s\" externalInfoUrl=\"%s\" "
+ + "priority=\"%s\">%s</violation>" + getNewLine(),
+ beginLine,
+ endLine,
+ beginColumn,
+ endColumn,
+ rule.getRuleName(),
+ ruleSetName,
+ violatedFile.getPackageName(),
+ violatedFile.getClassName(),
+ RULESET_CREATOR_URL
+ + extractShortName(rule.getName()),
+ rule.getPriority(),
+ message);
+ }
+ return formatter.toString();
+ }
+
+ /**
+ * @return
+ */
+ String getNewLine() {
+ return System.getProperty("line.separator");
+ }
+
+ private String extractShortName(final String name) {
+ return StringUtils.substringAfterLast(name,
+ ".");
+ }
+
+ private int getLinePriority(final IFlexViolation otherViolation) {
+ int res;
+
+ if (beginLine > otherViolation.getBeginLine()) {
+ res = 1;
+ } else if (beginLine < otherViolation.getBeginLine()) {
+ res = -1;
+ } else {
+ res = 0;
+ }
+
+ return res;
+ }
+
+ private int getPrioriyOrder(final IFlexViolation otherViolation) {
+ int res;
+
+ if (rule.getPriority().getPriority() > otherViolation.getRule().getPriority().getPriority()) {
+ res = 1;
+ } else if (rule.getPriority().getPriority() < otherViolation.getRule().getPriority().getPriority()) {
+ res = -1;
+ } else {
+ res = 0;
+ }
+
+ return res;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/ViolationPosition.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/ViolationPosition.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/ViolationPosition.java
new file mode 100644
index 0000000..c614473
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/ViolationPosition.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 org.apache.flex.pmd.rules.core;
+
+/**
+ * @author xagnetti
+ */
+public final class ViolationPosition {
+ /**
+ * @param beginLineToBeSet
+ * @param endLineToBeSet
+ * @param beginColumnToBeSet
+ * @param endColumnToBeSet
+ * @return
+ */
+ public static ViolationPosition create(final int beginLineToBeSet,
+ final int endLineToBeSet,
+ final int beginColumnToBeSet,
+ final int endColumnToBeSet) {
+ return new ViolationPosition(beginLineToBeSet, endLineToBeSet, beginColumnToBeSet, endColumnToBeSet);
+ }
+
+ private final int beginColumn;
+ private final int beginLine;
+ private final int endColumn;
+ private final int endLine;
+
+ /**
+ * @param lineToBeSet
+ */
+ public ViolationPosition(final int lineToBeSet) {
+ this(lineToBeSet, lineToBeSet, 0, 0);
+ }
+
+ /**
+ * @param beginLineToBeSet
+ * @param endLineToBeSet
+ */
+ public ViolationPosition(final int beginLineToBeSet,
+ final int endLineToBeSet) {
+ this(beginLineToBeSet, endLineToBeSet, 0, 0);
+ }
+
+ private ViolationPosition(final int beginLineToBeSet,
+ final int endLineToBeSet,
+ final int beginColumnToBeSet,
+ final int endColumnToBeSet) {
+ super();
+
+ beginLine = beginLineToBeSet;
+ beginColumn = beginColumnToBeSet;
+ endLine = endLineToBeSet;
+ endColumn = endColumnToBeSet;
+ }
+
+ /**
+ * @return
+ */
+ public int getBeginColumn() {
+ return beginColumn;
+ }
+
+ /**
+ * @return
+ */
+ public int getBeginLine() {
+ return beginLine;
+ }
+
+ /**
+ * @return
+ */
+ public int getEndColumn() {
+ return endColumn;
+ }
+
+ /**
+ * @return
+ */
+ public int getEndLine() {
+ return endLine;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/ViolationPriority.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/ViolationPriority.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/ViolationPriority.java
new file mode 100644
index 0000000..d46fc16
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/ViolationPriority.java
@@ -0,0 +1,42 @@
+/*
+ * 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 org.apache.flex.pmd.rules.core;
+
+/**
+ * @author xagnetti
+ */
+public enum ViolationPriority {
+ HIGH("1"), LOW("5"), NORMAL("3");
+
+ private String priority;
+
+ /**
+ * @param priorityToBeSet
+ */
+ private ViolationPriority(final String priorityToBeSet) {
+ priority = priorityToBeSet;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.lang.Enum#toString()
+ */
+ @Override
+ public String toString() {
+ return priority;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/thresholded/AbstractMaximizedAstFlexRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/thresholded/AbstractMaximizedAstFlexRule.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/thresholded/AbstractMaximizedAstFlexRule.java
new file mode 100644
index 0000000..d04260c
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/thresholded/AbstractMaximizedAstFlexRule.java
@@ -0,0 +1,43 @@
+/*
+ * 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 org.apache.flex.pmd.rules.core.thresholded;
+
+import org.apache.flex.pmd.rules.core.AbstractAstFlexRule;
+
+/**
+ * @author xagnetti
+ */
+public abstract class AbstractMaximizedAstFlexRule extends AbstractAstFlexRule implements IThresholdedRule {
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.thresholded.IThresholdedRule#getThreshold()
+ */
+ public final int getThreshold() {
+ return 1;//getIntProperty( propertyDescriptorFor( getThresholdName() ) );
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.thresholded.IThresholdedRule#getThresholdName
+ * ()
+ */
+ public final String getThresholdName() {
+ return MAXIMUM;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/thresholded/AbstractMaximizedFlexRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/thresholded/AbstractMaximizedFlexRule.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/thresholded/AbstractMaximizedFlexRule.java
new file mode 100644
index 0000000..22b293c
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/thresholded/AbstractMaximizedFlexRule.java
@@ -0,0 +1,43 @@
+/*
+ * 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 org.apache.flex.pmd.rules.core.thresholded;
+
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+
+/**
+ * @author xagnetti
+ */
+public abstract class AbstractMaximizedFlexRule extends AbstractFlexRule implements IThresholdedRule {
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.thresholded.IThresholdedRule#getThreshold()
+ */
+ public int getThreshold() {
+ return 0;//getIntProperty( propertyDescriptorFor( getThresholdName() ) );
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.thresholded.IThresholdedRule#getThresholdName
+ * ()
+ */
+ public final String getThresholdName() {
+ return MAXIMUM;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/thresholded/AbstractMaximizedRegexpBasedRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/thresholded/AbstractMaximizedRegexpBasedRule.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/thresholded/AbstractMaximizedRegexpBasedRule.java
new file mode 100644
index 0000000..7187789
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/thresholded/AbstractMaximizedRegexpBasedRule.java
@@ -0,0 +1,44 @@
+/*
+ * 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 org.apache.flex.pmd.rules.core.thresholded;
+
+import org.apache.flex.pmd.rules.core.AbstractRegexpBasedRule;
+
+/**
+ * @author xagnetti
+ */
+public abstract class AbstractMaximizedRegexpBasedRule extends AbstractRegexpBasedRule implements
+ IThresholdedRule {
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.thresholded.IThresholdedRule#getThreshold()
+ */
+ public final int getThreshold() {
+ return 1;//getIntProperty( propertyDescriptorFor( getThresholdName() ) );
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.thresholded.IThresholdedRule#getThresholdName
+ * ()
+ */
+ public final String getThresholdName() {
+ return MAXIMUM;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/thresholded/IThresholdedRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/thresholded/IThresholdedRule.java b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/thresholded/IThresholdedRule.java
new file mode 100644
index 0000000..5216a5c
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-api/src/main/java/org/apache/flex/pmd/rules/core/thresholded/IThresholdedRule.java
@@ -0,0 +1,44 @@
+/*
+ * 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 org.apache.flex.pmd.rules.core.thresholded;
+
+import org.apache.flex.pmd.rules.core.IFlexRule;
+
+/**
+ * @author xagnetti
+ */
+public interface IThresholdedRule extends IFlexRule {
+ /**
+ * @return
+ */
+ int getActualValueForTheCurrentViolation();
+
+ /**
+ * @return
+ */
+ int getDefaultThreshold();
+
+ /**
+ * @return
+ */
+ int getThreshold();
+
+ /**
+ * @return
+ */
+ String getThresholdName();
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/pom.xml
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/pom.xml b/FlexPMD/language-module/ruleset/ruleset-flex-basic/pom.xml
new file mode 100644
index 0000000..b60a384
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/pom.xml
@@ -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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.flex.pmd.ruleset</groupId>
+ <artifactId>ruleset</artifactId>
+ <version>2.0.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>ruleset-flex-basic</artifactId>
+ <version>2.0.0-SNAPSHOT</version>
+ <packaging>jar</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.flex.pmd.ruleset</groupId>
+ <artifactId>ruleset-api</artifactId>
+ <version>2.0.0-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.flex.pmd.parser</groupId>
+ <artifactId>parser-impl</artifactId>
+ <version>2.0.0-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.testng</groupId>
+ <artifactId>testng</artifactId>
+ <version>6.8.8</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/architecture/MonkeyPatchingRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/architecture/MonkeyPatchingRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/architecture/MonkeyPatchingRule.java
new file mode 100644
index 0000000..5445cdb
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/architecture/MonkeyPatchingRule.java
@@ -0,0 +1,67 @@
+/*
+ * 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 org.apache.flex.pmd.rules.architecture;
+
+import org.apache.flex.pmd.rules.IFlexViolation;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author xagnetti
+ */
+public class MonkeyPatchingRule extends AbstractFlexRule {
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractFlexRule#findViolationsInCurrentFile()
+ */
+ @Override
+ protected final List<IFlexViolation> findViolationsInCurrentFile() {
+ final List<IFlexViolation> violations = new ArrayList<IFlexViolation>();
+
+ if (getCurrentFile().getPackageName().startsWith("mx.")
+ && !getCurrentFile().getClassName().equals("Version.as")
+ && !getCurrentFile().getClassName().endsWith("Style.as")) {
+ addViolation(violations,
+ new ViolationPosition(0));
+ }
+ return violations;
+ }
+
+ /*
+ * (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.AbstractFlexRule#isConcernedByTheCurrentFile()
+ */
+ @Override
+ protected final boolean isConcernedByTheCurrentFile() {
+ return !getCurrentFile().isMxml();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/architecture/UseInternalClassOutsideApiClass.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/architecture/UseInternalClassOutsideApiClass.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/architecture/UseInternalClassOutsideApiClass.java
new file mode 100644
index 0000000..ae2144b
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/architecture/UseInternalClassOutsideApiClass.java
@@ -0,0 +1,113 @@
+/*
+ * 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 org.apache.flex.pmd.rules.architecture;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.flex.pmd.nodes.IPackage;
+import org.apache.flex.pmd.parser.IParserNode;
+import org.apache.flex.pmd.rules.core.AbstractAstFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+/**
+ * @author xagnetti
+ */
+public class UseInternalClassOutsideApiClass extends AbstractAstFlexRule {
+ private static final String API_PACKAGE_NAME = "api";
+ private static final String INTERNAL_PACKAGE_NAME = "restricted";
+ private static final String PACKAGE_SEPARATOR = ".";
+
+ /*
+ * (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();
+ final boolean isApiClass = isApiClass(packageName);
+ final boolean isInternalClass = isInternalClass(packageName);
+ String functionAreaName = null;
+
+ if (isApiClass
+ || isInternalClass) {
+ functionAreaName = extractFunctionalArea(packageName,
+ false);
+ }
+ for (final IParserNode importNode : packageNode.getImports()) {
+ final String importName = importNode.getStringValue();
+ final String importFunctionalArea = extractFunctionalArea(importName,
+ true);
+
+ if (doesLineContainPackageReference(importName,
+ INTERNAL_PACKAGE_NAME)
+ && (functionAreaName == null || !functionAreaName.equals(importFunctionalArea))) {
+ addViolation(importNode,
+ importName,
+ importFunctionalArea);
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority()
+ */
+ @Override
+ protected final ViolationPriority getDefaultPriority() {
+ return ViolationPriority.HIGH;
+ }
+
+ private boolean doesLineContainPackageReference(final String line,
+ final String packageName) {
+ return line.contains(PACKAGE_SEPARATOR
+ + packageName);
+ }
+
+ private String extractFunctionalArea(final String packageName,
+ final boolean isInImport) {
+ if (packageName.contains(INTERNAL_PACKAGE_NAME)) {
+ return extractFunctionArea(packageName,
+ INTERNAL_PACKAGE_NAME,
+ isInImport);
+ }
+ return extractFunctionArea(packageName,
+ API_PACKAGE_NAME,
+ isInImport);
+ }
+
+ private String extractFunctionArea(final String packageName,
+ final String visibilityPackageName,
+ final boolean isInImport) {
+ return StringUtils.substringAfterLast(StringUtils.substringBeforeLast(packageName,
+ PACKAGE_SEPARATOR
+ + visibilityPackageName
+ + (isInImport ? PACKAGE_SEPARATOR
+ : "")),
+ PACKAGE_SEPARATOR);
+ }
+
+ private boolean isApiClass(final String packageName) {
+ return doesLineContainPackageReference(packageName,
+ API_PACKAGE_NAME);
+ }
+
+ private boolean isInternalClass(final String packageName) {
+ return doesLineContainPackageReference(packageName,
+ INTERNAL_PACKAGE_NAME);
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/architecture/ViewComponentReferencedInModelRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/architecture/ViewComponentReferencedInModelRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/architecture/ViewComponentReferencedInModelRule.java
new file mode 100644
index 0000000..a8f9bfb
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/architecture/ViewComponentReferencedInModelRule.java
@@ -0,0 +1,83 @@
+/*
+ * 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 org.apache.flex.pmd.rules.architecture;
+
+import org.apache.flex.pmd.rules.core.AbstractRegexpBasedRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+import java.util.Locale;
+import java.util.regex.Matcher;
+
+/**
+ * @author xagnetti
+ */
+public class ViewComponentReferencedInModelRule extends AbstractRegexpBasedRule // NO_UCD
+{
+ private static final String ALERT_CLASS_NAME = "Alert";
+ private static final String FLEX_CONTROLS_PACKAGE_NAME = "mx.controls";
+ private static final String MODEL_CLASS_SUFFIX = "model";
+ private static final String MODEL_PACKAGE_NAME = ".model";
+ private static final String VIEW_PACKAGE_NAME = ".view";
+
+ /*
+ * (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.AbstractRegexpBasedRule#getRegexp()
+ */
+ @Override
+ protected final String getRegexp() {
+ return ".*import (.*);?.*";
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractFlexRule#isConcernedByTheCurrentFile()
+ */
+ @Override
+ protected final boolean isConcernedByTheCurrentFile() {
+ return !getCurrentFile().isMxml()
+ && getCurrentFile().getFullyQualifiedName()
+ .toLowerCase(Locale.ENGLISH)
+ .contains(MODEL_CLASS_SUFFIX);
+ }
+
+ /*
+ * (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);
+
+ matcher.matches();
+ final String importedClass = matcher.group(1);
+
+ return importedClass.contains(FLEX_CONTROLS_PACKAGE_NAME)
+ && !importedClass.contains(ALERT_CLASS_NAME) || importedClass.contains(VIEW_PACKAGE_NAME)
+ && !importedClass.contains(MODEL_PACKAGE_NAME);
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/asdocs/AbstractAsDocRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/asdocs/AbstractAsDocRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/asdocs/AbstractAsDocRule.java
new file mode 100644
index 0000000..7a0d08a
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/asdocs/AbstractAsDocRule.java
@@ -0,0 +1,34 @@
+/*
+ * 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 org.apache.flex.pmd.rules.asdocs;
+
+import org.apache.flex.pmd.nodes.IAsDocHolder;
+import org.apache.flex.pmd.rules.core.AbstractAstFlexRule;
+
+/**
+ * @author xagnetti
+ */
+abstract class AbstractAsDocRule extends AbstractAstFlexRule {
+ /**
+ * @param asDocHolder
+ */
+ protected void addViolationIfAsDocMissing(final IAsDocHolder asDocHolder) {
+ if (asDocHolder.getAsDoc() == null) {
+ addViolation(asDocHolder);
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/asdocs/AttributeAsDocMissingRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/asdocs/AttributeAsDocMissingRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/asdocs/AttributeAsDocMissingRule.java
new file mode 100644
index 0000000..575ee45
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/asdocs/AttributeAsDocMissingRule.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.flex.pmd.rules.asdocs;
+
+import org.apache.flex.pmd.nodes.IAttribute;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+import java.util.List;
+
+/**
+ * @author xagnetti
+ */
+public class AttributeAsDocMissingRule extends AbstractAsDocRule {
+ /*
+ * (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) {
+ addViolationIfAsDocMissing(attribute);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority()
+ */
+ @Override
+ protected ViolationPriority getDefaultPriority() {
+ return ViolationPriority.NORMAL;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/asdocs/ClassAsDocMissingRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/asdocs/ClassAsDocMissingRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/asdocs/ClassAsDocMissingRule.java
new file mode 100644
index 0000000..918d230
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/asdocs/ClassAsDocMissingRule.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 org.apache.flex.pmd.rules.asdocs;
+
+import org.apache.flex.pmd.nodes.IClass;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+/**
+ * @author xagnetti
+ */
+public class ClassAsDocMissingRule extends AbstractAsDocRule {
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#isConcernedByTheCurrentFile
+ * ()
+ */
+ @Override
+ public 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) {
+ addViolationIfAsDocMissing(classNode);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority()
+ */
+ @Override
+ protected ViolationPriority getDefaultPriority() {
+ return ViolationPriority.NORMAL;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/asdocs/MethodAsDocMissingRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/asdocs/MethodAsDocMissingRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/asdocs/MethodAsDocMissingRule.java
new file mode 100644
index 0000000..6797828
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/asdocs/MethodAsDocMissingRule.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.flex.pmd.rules.asdocs;
+
+import org.apache.flex.pmd.nodes.IFunction;
+import org.apache.flex.pmd.nodes.Modifier;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+/**
+ * @author xagnetti
+ */
+public class MethodAsDocMissingRule extends AbstractAsDocRule {
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#findViolations(com.adobe
+ * .ac.pmd.nodes.IFunction)
+ */
+ @Override
+ protected void findViolations(final IFunction function) {
+ if ((function.isPublic() || function.is(Modifier.PROTECTED))
+ && !function.isGetter() && !function.isSetter() && function.getAsDoc() == null) {
+ addViolation(function);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority()
+ */
+ @Override
+ protected ViolationPriority getDefaultPriority() {
+ return ViolationPriority.NORMAL;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/binding/BindingUtilsRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/binding/BindingUtilsRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/binding/BindingUtilsRule.java
new file mode 100644
index 0000000..e5629d6
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/binding/BindingUtilsRule.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 org.apache.flex.pmd.rules.binding;
+
+import org.apache.flex.pmd.rules.core.AbstractForbiddenImportRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+/**
+ * @author xagnetti
+ */
+public class BindingUtilsRule extends AbstractForbiddenImportRule // NO_UCD
+{
+ /*
+ * (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.AbstractForbiddenImportRule#getForbiddenImport
+ * ()
+ */
+ @Override
+ protected String getForbiddenImport() {
+ return "BindingUtils";
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/binding/ChangeWatcherRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/binding/ChangeWatcherRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/binding/ChangeWatcherRule.java
new file mode 100644
index 0000000..da5b105
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/binding/ChangeWatcherRule.java
@@ -0,0 +1,45 @@
+/*
+ * 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 org.apache.flex.pmd.rules.binding;
+
+import org.apache.flex.pmd.rules.core.AbstractForbiddenImportRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+/**
+ * @author xagnetti
+ */
+public class ChangeWatcherRule extends AbstractForbiddenImportRule {
+ /*
+ * (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.AbstractForbiddenImportRule#getForbiddenImport
+ * ()
+ */
+ @Override
+ protected String getForbiddenImport() {
+ return "ChangeWatcher";
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/binding/TooLongBindingExpressionRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/binding/TooLongBindingExpressionRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/binding/TooLongBindingExpressionRule.java
new file mode 100644
index 0000000..0d58ec0
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/binding/TooLongBindingExpressionRule.java
@@ -0,0 +1,106 @@
+/*
+ * 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 org.apache.flex.pmd.rules.binding;
+
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+import org.apache.flex.pmd.rules.core.thresholded.AbstractMaximizedRegexpBasedRule;
+
+import java.util.regex.Matcher;
+
+/**
+ * @author xagnetti
+ */
+public class TooLongBindingExpressionRule extends AbstractMaximizedRegexpBasedRule // NO_UCD
+{
+ private int currentCount;
+
+ /*
+ * (non-Javadoc)
+ * @seecom.adobe.ac.pmd.rules.core.thresholded.IThresholdedRule#
+ * getActualValueForTheCurrentViolation()
+ */
+ public final int getActualValueForTheCurrentViolation() {
+ return currentCount;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.thresholded.IThresholdedRule#getDefaultThreshold
+ * ()
+ */
+ public final int getDefaultThreshold() {
+ return 2;
+ }
+
+ /*
+ * (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.AbstractRegexpBasedRule#getRegexp()
+ */
+ @Override
+ protected final String getRegexp() {
+ return ".*=\"\\{[^']([^\\}]*)[^']\\}\".*";
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractFlexRule#isConcernedByTheCurrentFile()
+ */
+ @Override
+ protected final boolean isConcernedByTheCurrentFile() {
+ return getCurrentFile().isMxml();
+ }
+
+ /*
+ * (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);
+
+ matcher.matches();
+ currentCount = countChar(matcher.group(1),
+ '.');
+ return matcher.matches()
+ && currentCount > getThreshold();
+ }
+
+ private int countChar(final String input,
+ final char charToSearch) {
+ int charCount = 0;
+
+ for (int i = 0; i < input.length(); i++) {
+ if (input.charAt(i) == charToSearch) {
+ charCount++;
+ }
+ }
+
+ return charCount;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/cairngorm/BadCairngormEventNameFormatRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/cairngorm/BadCairngormEventNameFormatRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/cairngorm/BadCairngormEventNameFormatRule.java
new file mode 100644
index 0000000..0a81fac
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/cairngorm/BadCairngormEventNameFormatRule.java
@@ -0,0 +1,105 @@
+/*
+ * 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 org.apache.flex.pmd.rules.cairngorm;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.flex.pmd.nodes.IClass;
+import org.apache.flex.pmd.nodes.IField;
+import org.apache.flex.pmd.nodes.IFunction;
+import org.apache.flex.pmd.parser.IParserNode;
+import org.apache.flex.pmd.rules.core.AbstractAstFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+/**
+ * @author xagnetti
+ */
+public class BadCairngormEventNameFormatRule extends AbstractAstFlexRule // NO_UCD
+{
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#isConcernedByTheCurrentFile
+ * ()
+ */
+ @Override
+ public final boolean isConcernedByTheCurrentFile() {
+ return getCurrentFile().getClassName().endsWith("Event.as");
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#findViolations(com.adobe
+ * .ac.pmd.nodes.IClass)
+ */
+ @Override
+ protected final void findViolations(final IClass classNode) {
+ if (isExtendedClassCairngormEvent(classNode)) {
+ final String eventName = extractEventName(classNode);
+
+ if (StringUtils.isEmpty(eventName)
+ || !eventName.contains(".")) {
+ addViolation(classNode);
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority()
+ */
+ @Override
+ protected final ViolationPriority getDefaultPriority() {
+ return ViolationPriority.NORMAL;
+ }
+
+ private String extractEventName(final IClass classNode) {
+ String eventName = "";
+
+ for (final IField constantNode : classNode.getConstants()) {
+ if (constantNode.getName().startsWith("EVENT")) {
+ eventName = extractEventNameFromConstant(constantNode.getInitializationExpression()
+ .getInternalNode());
+ }
+ }
+ if (StringUtils.isEmpty(eventName)
+ && classNode.getConstructor() != null) {
+ eventName = extractEventNameFromConstructor(classNode.getConstructor());
+ }
+ return eventName;
+ }
+
+ private String extractEventNameFromConstant(final IParserNode initExpressionNode) {
+ return initExpressionNode.getChild(0).getStringValue();
+ }
+
+ private String extractEventNameFromConstructor(final IFunction constructor) {
+ String eventName = "";
+ final IParserNode superCall = constructor.getSuperCall();
+
+ if (superCall != null) {
+ eventName = superCall.getChild(1).getChild(0).getStringValue();
+ }
+ return eventName;
+ }
+
+ private boolean isExtendedClassCairngormEvent(final IClass classNode) {
+ return classNode.getExtensionName() != null
+ && classNode.getExtensionName().contains("Cairngorm")
+ && classNode.getExtensionName().contains("Event");
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/cairngorm/BindableModelLocatorRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/cairngorm/BindableModelLocatorRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/cairngorm/BindableModelLocatorRule.java
new file mode 100644
index 0000000..bc99c08
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/cairngorm/BindableModelLocatorRule.java
@@ -0,0 +1,60 @@
+/*
+ * 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 org.apache.flex.pmd.rules.cairngorm;
+
+import org.apache.flex.pmd.nodes.IClass;
+import org.apache.flex.pmd.rules.core.AbstractAstFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+/**
+ * @author xagnetti
+ */
+public class BindableModelLocatorRule extends AbstractAstFlexRule // NO_UCD
+{
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#isConcernedByTheCurrentFile
+ * ()
+ */
+ @Override
+ public final boolean isConcernedByTheCurrentFile() {
+ return getCurrentFile().getClassName().endsWith("ModelLocator.as");
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#findViolations(com.adobe
+ * .ac.pmd.nodes.IClass)
+ */
+ @Override
+ protected final void findViolations(final IClass classNode) {
+ if (classNode.isBindable()) {
+ addViolation(classNode);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority()
+ */
+ @Override
+ protected final ViolationPriority getDefaultPriority() {
+ return ViolationPriority.HIGH;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/cairngorm/CairngormEventDispatcherCallExplicitlyRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/cairngorm/CairngormEventDispatcherCallExplicitlyRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/cairngorm/CairngormEventDispatcherCallExplicitlyRule.java
new file mode 100644
index 0000000..64c2b9f
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/cairngorm/CairngormEventDispatcherCallExplicitlyRule.java
@@ -0,0 +1,71 @@
+/*
+ * 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 org.apache.flex.pmd.rules.cairngorm;
+
+import org.apache.flex.pmd.nodes.IFunction;
+import org.apache.flex.pmd.parser.IParserNode;
+import org.apache.flex.pmd.rules.core.AbstractPrimaryAstRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+/**
+ * @author xagnetti
+ */
+public class CairngormEventDispatcherCallExplicitlyRule extends AbstractPrimaryAstRule // NO_UCD
+{
+ private static final String ADD_EVENT_LISTENER_MESSAGE = "The Cairngorm event is listened directly. "
+ + "The Controller is then avoided, and "
+ + "the MVC pattern is broken.";
+ private static final String DISPATCH_EVENT = "dispatchEvent";
+ private static final String DISPATCH_EVENT_MESSAGE = "Use cairngormEvent.dispatch instead";
+ private static final String EVENT_DISPATCHER = "CairngormEventDispatcher";
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractPrimaryAstRule#addViolation(com.adobe
+ * .ac.pmd.parser.IParserNode, com.adobe.ac.pmd.nodes.IFunction)
+ */
+ @Override
+ protected void addViolation(final IParserNode statement,
+ final IFunction function) {
+ final String violationLine = getCurrentFile().getLineAt(statement.getLine());
+ final String messageToAppend = violationLine.contains(DISPATCH_EVENT) ? ADD_EVENT_LISTENER_MESSAGE
+ : DISPATCH_EVENT_MESSAGE;
+
+ addViolation(statement,
+ messageToAppend);
+ }
+
+ /*
+ * (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.AbstractPrimaryAstRule#getFirstPrimaryToFind()
+ */
+ @Override
+ protected String getFirstPrimaryToFind() {
+ return EVENT_DISPATCHER;
+ }
+}
[09/24] git commit: [flex-utilities]
[refs/heads/feature/pmd-5.2-language-module] - Initial commit of the PMD
language module for Apache Flex
Posted by cd...@apache.org.
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/cairngorm/CairngormEventDispatcherCallExplicitlyRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/cairngorm/CairngormEventDispatcherCallExplicitlyRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/cairngorm/CairngormEventDispatcherCallExplicitlyRuleTest.java
new file mode 100644
index 0000000..8e73371
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/cairngorm/CairngormEventDispatcherCallExplicitlyRuleTest.java
@@ -0,0 +1,36 @@
+/*
+ * 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 org.apache.flex.pmd.rules.cairngorm;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class CairngormEventDispatcherCallExplicitlyRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("AbstractRowData.as", new ViolationPosition[]
+ {new ViolationPosition(98),
+ new ViolationPosition(102)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new CairngormEventDispatcherCallExplicitlyRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/cairngorm/FatControllerRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/cairngorm/FatControllerRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/cairngorm/FatControllerRuleTest.java
new file mode 100644
index 0000000..813c4f4
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/cairngorm/FatControllerRuleTest.java
@@ -0,0 +1,35 @@
+/*
+ * 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 org.apache.flex.pmd.rules.cairngorm;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class FatControllerRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("cairngorm.FatController.as", new ViolationPosition[]
+ {new ViolationPosition(83)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new FatControllerRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/cairngorm/ModelLocatorReferencedMoreThanOncePerClassRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/cairngorm/ModelLocatorReferencedMoreThanOncePerClassRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/cairngorm/ModelLocatorReferencedMoreThanOncePerClassRuleTest.java
new file mode 100644
index 0000000..33ee61f
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/cairngorm/ModelLocatorReferencedMoreThanOncePerClassRuleTest.java
@@ -0,0 +1,35 @@
+/*
+ * 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 org.apache.flex.pmd.rules.cairngorm;
+
+import org.apache.flex.pmd.rules.core.AbstractRegexpBasedRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class ModelLocatorReferencedMoreThanOncePerClassRuleTest extends
+ ReferenceModelLocatorOutsideTheMainApplicationRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("UnboundMetadata.as", new ViolationPosition[]
+ {new ViolationPosition(38)})};
+ }
+
+ @Override
+ protected AbstractRegexpBasedRule getRegexpBasedRule() {
+ return new ModelLocatorReferencedMoreThanOncePerClassRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/cairngorm/ReferenceModelLocatorOutsideTheMainApplicationRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/cairngorm/ReferenceModelLocatorOutsideTheMainApplicationRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/cairngorm/ReferenceModelLocatorOutsideTheMainApplicationRuleTest.java
new file mode 100644
index 0000000..4da250c
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/cairngorm/ReferenceModelLocatorOutsideTheMainApplicationRuleTest.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 org.apache.flex.pmd.rules.cairngorm;
+
+import org.apache.flex.pmd.rules.AbstractRegExpBasedRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractRegexpBasedRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class ReferenceModelLocatorOutsideTheMainApplicationRuleTest extends AbstractRegExpBasedRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("UnboundMetadata.as", new ViolationPosition[]
+ {new ViolationPosition(31),
+ new ViolationPosition(33),
+ new ViolationPosition(38)}),
+ new ExpectedViolation("com.adobe.ac.ncss.mxml.IterationsList.mxml",
+ new ViolationPosition[]
+ {new ViolationPosition(77),
+ new ViolationPosition(79)})};
+ }
+
+ @Override
+ protected String[] getMatchableLines() {
+ return new String[]
+ {"ModelLocator",
+ "import com.my.MyModelLocator;"};
+ }
+
+ @Override
+ protected AbstractRegexpBasedRule getRegexpBasedRule() {
+ return new ReferenceModelLocatorOutsideTheMainApplicationRule();
+ }
+
+ @Override
+ protected String[] getUnmatchableLines() {
+ return new String[]
+ {"ModfrelLocator",
+ "import com.my.MyModelLocafrtor;"};
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/component/CallLaterDirectlyRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/component/CallLaterDirectlyRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/component/CallLaterDirectlyRuleTest.java
new file mode 100644
index 0000000..492cd4e
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/component/CallLaterDirectlyRuleTest.java
@@ -0,0 +1,36 @@
+/*
+ * 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 org.apache.flex.pmd.rules.component;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class CallLaterDirectlyRuleTest extends AbstractAstFlexRuleTest {
+
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("GenericType.as", new ViolationPosition[]
+ {new ViolationPosition(29)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new CallLaterDirectlyRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/component/UpdateChildrenNumberInUpdateDisplayListRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/component/UpdateChildrenNumberInUpdateDisplayListRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/component/UpdateChildrenNumberInUpdateDisplayListRuleTest.java
new file mode 100644
index 0000000..47e77f2
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/component/UpdateChildrenNumberInUpdateDisplayListRuleTest.java
@@ -0,0 +1,38 @@
+/*
+ * 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 org.apache.flex.pmd.rules.component;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class UpdateChildrenNumberInUpdateDisplayListRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("BadComponent.as", new ViolationPosition[]
+ {new ViolationPosition(30),
+ new ViolationPosition(31),
+ new ViolationPosition(32),
+ new ViolationPosition(33)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new UpdateChildrenNumberInUpdateDisplayListRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/css/StyleBlockInMxmlRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/css/StyleBlockInMxmlRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/css/StyleBlockInMxmlRuleTest.java
new file mode 100644
index 0000000..8c42094
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/css/StyleBlockInMxmlRuleTest.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 org.apache.flex.pmd.rules.css;
+
+import org.apache.flex.pmd.rules.AbstractRegExpBasedRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractRegexpBasedRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class StyleBlockInMxmlRuleTest extends AbstractRegExpBasedRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("Main.mxml", new ViolationPosition[]
+ {new ViolationPosition(38)})};
+ }
+
+ @Override
+ protected String[] getMatchableLines() {
+ return new String[]
+ {"<mx:Style>",
+ " <mx:Style> ",
+ "<mx:Style> ",
+ " <mx:Style>"};
+ }
+
+ @Override
+ protected AbstractRegexpBasedRule getRegexpBasedRule() {
+ return new StyleBlockInMxmlRule();
+ }
+
+ @Override
+ protected String[] getUnmatchableLines() {
+ return new String[]
+ {"<mx:VBox",
+ "<Box",
+ "<Canvas",
+ "<VBox",
+ "<mx:HBox",
+ "<Accordion",
+ "<Form",
+ "<FormItem",
+ "<LayoutContainer",
+ "<Panel",
+ "<ViewStack",
+ "<mx:Style/>"};
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/css/UseCssInsteadOfEmbedMetaDataRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/css/UseCssInsteadOfEmbedMetaDataRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/css/UseCssInsteadOfEmbedMetaDataRuleTest.java
new file mode 100644
index 0000000..593fb2a
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/css/UseCssInsteadOfEmbedMetaDataRuleTest.java
@@ -0,0 +1,35 @@
+/*
+ * 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 org.apache.flex.pmd.rules.css;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class UseCssInsteadOfEmbedMetaDataRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("Title.as", new ViolationPosition[]
+ {new ViolationPosition(26)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new UseCssInsteadOfEmbedMetaDataRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/empty/EmptyCatchStatementRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/empty/EmptyCatchStatementRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/empty/EmptyCatchStatementRuleTest.java
new file mode 100644
index 0000000..b210930
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/empty/EmptyCatchStatementRuleTest.java
@@ -0,0 +1,35 @@
+/*
+ * 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 org.apache.flex.pmd.rules.empty;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class EmptyCatchStatementRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("com.adobe.ac.ncss.ConfigProxy.as", new ViolationPosition[]
+ {new ViolationPosition(45)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new EmptyCatchStatementRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/empty/EmptyIfStmtRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/empty/EmptyIfStmtRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/empty/EmptyIfStmtRuleTest.java
new file mode 100644
index 0000000..25765b0
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/empty/EmptyIfStmtRuleTest.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 org.apache.flex.pmd.rules.empty;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class EmptyIfStmtRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("bug.Duane.mxml", new ViolationPosition[]
+ {new ViolationPosition(77),
+ new ViolationPosition(73),
+ new ViolationPosition(69)}),
+ new ExpectedViolation("PngEncoder.as", new ViolationPosition[]
+ {new ViolationPosition(561),
+ new ViolationPosition(567)}),
+ new ExpectedViolation("RadonDataGrid.as", new ViolationPosition[]
+ {new ViolationPosition(51),
+ new ViolationPosition(178)}),
+ new ExpectedViolation("AbstractRowData.as", new ViolationPosition[]
+ {new ViolationPosition(94),
+ new ViolationPosition(101)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new EmptyIfStmtRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/event/ConstructorDispatchingEventRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/event/ConstructorDispatchingEventRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/event/ConstructorDispatchingEventRuleTest.java
new file mode 100644
index 0000000..ec2ea54
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/event/ConstructorDispatchingEventRuleTest.java
@@ -0,0 +1,35 @@
+/*
+ * 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 org.apache.flex.pmd.rules.event;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class ConstructorDispatchingEventRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("com.adobe.ac.ncss.BigImporterModel.as", new ViolationPosition[]
+ {new ViolationPosition(46)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new ConstructorDispatchingEventRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/event/DefaultEventNameRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/event/DefaultEventNameRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/event/DefaultEventNameRuleTest.java
new file mode 100644
index 0000000..a44808d
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/event/DefaultEventNameRuleTest.java
@@ -0,0 +1,35 @@
+/*
+ * 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 org.apache.flex.pmd.rules.event;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class DefaultEventNameRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("DefaultNameEvent.as", new ViolationPosition[]
+ {new ViolationPosition(26)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new DefaultEventNameRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/event/DispatchHardCodedEventNameRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/event/DispatchHardCodedEventNameRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/event/DispatchHardCodedEventNameRuleTest.java
new file mode 100644
index 0000000..f596bf0
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/event/DispatchHardCodedEventNameRuleTest.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 org.apache.flex.pmd.rules.event;
+
+import org.apache.flex.pmd.rules.AbstractRegExpBasedRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractRegexpBasedRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class DispatchHardCodedEventNameRuleTest extends AbstractRegExpBasedRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("com.adobe.ac.ncss.BigImporterModel.as", new ViolationPosition[]
+ {new ViolationPosition(46)}),
+ new ExpectedViolation("AbstractRowData.as", new ViolationPosition[]
+ {new ViolationPosition(98),
+ new ViolationPosition(99)})};
+ }
+
+ @Override
+ protected String[] getMatchableLines() {
+ return new String[]
+ {"dispatchEvent(new Event(\"change\" ));",
+ "dispatchEvent( new Event('change') );",
+ "dispatchEvent(new Event(\"change\"));",
+ "dispatchEvent( new Event( 'selectedGroupFieldsChange' ) )"};
+ }
+
+ @Override
+ protected AbstractRegexpBasedRule getRegexpBasedRule() {
+ return new DispatchHardCodedEventNameRule();
+ }
+
+ @Override
+ protected String[] getUnmatchableLines() {
+ return new String[]
+ {"var i : int = 0;",
+ "lala();",
+ "dispatchEvent( new Event( CONST ) );",
+ "dispatchEvent(new Event(Rule.CONST));"};
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/event/EventMissingCloneFunctionRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/event/EventMissingCloneFunctionRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/event/EventMissingCloneFunctionRuleTest.java
new file mode 100644
index 0000000..e6da834
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/event/EventMissingCloneFunctionRuleTest.java
@@ -0,0 +1,38 @@
+/*
+ * 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 org.apache.flex.pmd.rules.event;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class EventMissingCloneFunctionRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("com.adobe.ac.ncss.SearchBarEvent.as", new ViolationPosition[]
+ {new ViolationPosition(23)}),
+ new ExpectedViolation("com.adobe.ac.ncss.event.FirstCustomEvent.as",
+ new ViolationPosition[]
+ {new ViolationPosition(21)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new EventMissingCloneFunctionRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/event/ListenForHardCodedEventNameRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/event/ListenForHardCodedEventNameRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/event/ListenForHardCodedEventNameRuleTest.java
new file mode 100644
index 0000000..8af635d
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/event/ListenForHardCodedEventNameRuleTest.java
@@ -0,0 +1,52 @@
+/*
+ * 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 org.apache.flex.pmd.rules.event;
+
+import org.apache.flex.pmd.rules.AbstractRegExpBasedRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractRegexpBasedRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class ListenForHardCodedEventNameRuleTest extends AbstractRegExpBasedRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("AbstractRowData.as", new ViolationPosition[]
+ {new ViolationPosition(97)})};
+ }
+
+ @Override
+ protected String[] getMatchableLines() {
+ return new String[]
+ {"addEventListener( \"change\", handleChange );",
+ "addEventListener( 'change', handleChange );",
+ "addEventListener(\"change\",handleChange);",
+ "addEventListener( \"change\","};
+ }
+
+ @Override
+ protected AbstractRegexpBasedRule getRegexpBasedRule() {
+ return new ListenForHardCodedEventNameRule();
+ }
+
+ @Override
+ protected String[] getUnmatchableLines() {
+ return new String[]
+ {"addEventListener( CHANGE, handleChange );",
+ "addEventListener(CHANGE,handleChange);",
+ "addEventListener( CHANGE,"};
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/event/PublicVariableInCustomEventRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/event/PublicVariableInCustomEventRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/event/PublicVariableInCustomEventRuleTest.java
new file mode 100644
index 0000000..77e38c7
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/event/PublicVariableInCustomEventRuleTest.java
@@ -0,0 +1,38 @@
+/*
+ * 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 org.apache.flex.pmd.rules.event;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class PublicVariableInCustomEventRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("com.adobe.ac.ncss.event.DynamicCustomEvent.as", new ViolationPosition[]
+ {new ViolationPosition(23)}),
+ new ExpectedViolation("com.adobe.ac.ncss.event.FirstCustomEvent.as",
+ new ViolationPosition[]
+ {new ViolationPosition(23)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new PublicVariableInCustomEventRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/event/UnboundTypeInMetadataRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/event/UnboundTypeInMetadataRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/event/UnboundTypeInMetadataRuleTest.java
new file mode 100644
index 0000000..fa69834
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/event/UnboundTypeInMetadataRuleTest.java
@@ -0,0 +1,37 @@
+/*
+ * 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 org.apache.flex.pmd.rules.event;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class UnboundTypeInMetadataRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("bug.Nico.as", new ViolationPosition[]
+ {new ViolationPosition(24)}),
+ new ExpectedViolation("UnboundMetadata.as", new ViolationPosition[]
+ {new ViolationPosition(26)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new UnboundTypeInMetadataRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/event/UntypedEventMetadataRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/event/UntypedEventMetadataRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/event/UntypedEventMetadataRuleTest.java
new file mode 100644
index 0000000..20dc243
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/event/UntypedEventMetadataRuleTest.java
@@ -0,0 +1,35 @@
+/*
+ * 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 org.apache.flex.pmd.rules.event;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class UntypedEventMetadataRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("UnboundMetadata.as", new ViolationPosition[]
+ {new ViolationPosition(27)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new UntypedEventMetadataRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/flexunit/EmptyUnitTestTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/flexunit/EmptyUnitTestTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/flexunit/EmptyUnitTestTest.java
new file mode 100644
index 0000000..a3552c2
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/flexunit/EmptyUnitTestTest.java
@@ -0,0 +1,38 @@
+/*
+ * 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 org.apache.flex.pmd.rules.flexunit;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class EmptyUnitTestTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("flexunit.RaoulTest.as", new ViolationPosition[]
+ {new ViolationPosition(42),
+ new ViolationPosition(48)}),
+ new ExpectedViolation("flexunit.RulesetTest.as", new ViolationPosition[]
+ {new ViolationPosition(36)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new EmptyUnitTest();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/AlertShowRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/AlertShowRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/AlertShowRuleTest.java
new file mode 100644
index 0000000..d05fe33
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/AlertShowRuleTest.java
@@ -0,0 +1,44 @@
+/*
+ * 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 org.apache.flex.pmd.rules.maintanability;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class AlertShowRuleTest extends AbstractAstFlexRuleTest {
+ public static final ExpectedViolation[] VIOLATING_FILES = new ExpectedViolation[]
+ {new ExpectedViolation("flexpmd114.a.Test.as",
+ new ViolationPosition[]
+ {new ViolationPosition(31)}),
+ new ExpectedViolation("flexpmd114.b.Test.as", new ViolationPosition[]
+ {new ViolationPosition(31)}),
+ new ExpectedViolation("flexpmd114.c.Test.as", new ViolationPosition[]
+ {new ViolationPosition(31)}),
+ new ExpectedViolation("com.adobe.ac.ncss.ConfigProxy.as", new ViolationPosition[]
+ {new ViolationPosition(36)})};
+
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return VIOLATING_FILES;
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new AlertShowRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/ArrayFieldWithNoArrayElementTypeRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/ArrayFieldWithNoArrayElementTypeRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/ArrayFieldWithNoArrayElementTypeRuleTest.java
new file mode 100644
index 0000000..e4db2f4
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/ArrayFieldWithNoArrayElementTypeRuleTest.java
@@ -0,0 +1,37 @@
+/*
+ * 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 org.apache.flex.pmd.rules.maintanability;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class ArrayFieldWithNoArrayElementTypeRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("fu.main.flex.TestRunnerApplication.mxml", new ViolationPosition[]
+ {new ViolationPosition(34)}),
+ new ExpectedViolation("bug.FlexPMD233b.mxml", new ViolationPosition[]
+ {new ViolationPosition(52)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new ArrayFieldWithNoArrayElementTypeRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/AvoidProtectedFieldInFinalClassRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/AvoidProtectedFieldInFinalClassRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/AvoidProtectedFieldInFinalClassRuleTest.java
new file mode 100644
index 0000000..1fd4196
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/AvoidProtectedFieldInFinalClassRuleTest.java
@@ -0,0 +1,36 @@
+/*
+ * 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 org.apache.flex.pmd.rules.maintanability;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class AvoidProtectedFieldInFinalClassRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("AbstractRowData.as", new ViolationPosition[]
+ {new ViolationPosition(32),
+ new ViolationPosition(77)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new AvoidProtectedFieldInFinalClassRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/AvoidUseOfAsKeywordRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/AvoidUseOfAsKeywordRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/AvoidUseOfAsKeywordRuleTest.java
new file mode 100644
index 0000000..dca8bec
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/AvoidUseOfAsKeywordRuleTest.java
@@ -0,0 +1,74 @@
+/*
+ * 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 org.apache.flex.pmd.rules.maintanability;
+
+import net.sourceforge.pmd.PMDException;
+import org.apache.flex.pmd.files.impl.FileUtils;
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+import java.io.File;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.logging.Logger;
+
+public class AvoidUseOfAsKeywordRuleTest extends AbstractAstFlexRuleTest {
+ protected static final Logger LOGGER = Logger.getLogger(AvoidUseOfAsKeywordRuleTest.class.getName());
+ private static final String TEST_FOLDER = "/com/adobe/ac/ncss";
+
+ public AvoidUseOfAsKeywordRuleTest() {
+ super();
+ final URL resource = this.getClass().getResource("/test"
+ + TEST_FOLDER);
+
+ if (resource != null) {
+ try {
+ setTestFiles(FileUtils.computeFilesList(new File(resource.toURI().getPath()),
+ null,
+ "",
+ null));
+ } catch (final PMDException e) {
+ LOGGER.warning(e.getLocalizedMessage());
+ } catch (final URISyntaxException e) {
+ LOGGER.warning(e.getLocalizedMessage());
+ }
+ }
+ }
+
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("LongSwitch.as", new ViolationPosition[]
+ {new ViolationPosition(48),
+ new ViolationPosition(49)}),
+ new ExpectedViolation("NestedSwitch.as", new ViolationPosition[]
+ {new ViolationPosition(38),
+ new ViolationPosition(39)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new AvoidUseOfAsKeywordRule();
+ }
+
+ @Override
+ protected File getTestDirectory() {
+ return new File(super.getTestDirectory().getAbsolutePath()
+ + TEST_FOLDER);
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/AvoidUsingPublicStaticFieldRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/AvoidUsingPublicStaticFieldRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/AvoidUsingPublicStaticFieldRuleTest.java
new file mode 100644
index 0000000..28aec5a
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/AvoidUsingPublicStaticFieldRuleTest.java
@@ -0,0 +1,37 @@
+/*
+ * 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 org.apache.flex.pmd.rules.maintanability;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class AvoidUsingPublicStaticFieldRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("bug.FlexPMD115.as", new ViolationPosition[]
+ {new ViolationPosition(24)}),
+ new ExpectedViolation("Sorted.as", new ViolationPosition[]
+ {new ViolationPosition(35)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new AvoidUsingPublicStaticFieldRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/AvoidUsingWithKeyWordRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/AvoidUsingWithKeyWordRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/AvoidUsingWithKeyWordRuleTest.java
new file mode 100644
index 0000000..56b3c9e
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/AvoidUsingWithKeyWordRuleTest.java
@@ -0,0 +1,35 @@
+/*
+ * 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 org.apache.flex.pmd.rules.maintanability;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class AvoidUsingWithKeyWordRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("GoodComponent.as", new ViolationPosition[]
+ {new ViolationPosition(42)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new AvoidUsingWithKeyWordRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/ClassAndExtensionAreIdenticalRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/ClassAndExtensionAreIdenticalRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/ClassAndExtensionAreIdenticalRuleTest.java
new file mode 100644
index 0000000..247c429
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/ClassAndExtensionAreIdenticalRuleTest.java
@@ -0,0 +1,35 @@
+/*
+ * 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 org.apache.flex.pmd.rules.maintanability;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class ClassAndExtensionAreIdenticalRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("GenericType.as", new ViolationPosition[]
+ {new ViolationPosition(21)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new ClassAndExtensionAreIdenticalRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/DynamicClassRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/DynamicClassRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/DynamicClassRuleTest.java
new file mode 100644
index 0000000..b284a28
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/DynamicClassRuleTest.java
@@ -0,0 +1,35 @@
+/*
+ * 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 org.apache.flex.pmd.rules.maintanability;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class DynamicClassRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("com.adobe.ac.ncss.event.DynamicCustomEvent.as", new ViolationPosition[]
+ {new ViolationPosition(21)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new DynamicClassRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/EmptyStatementRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/EmptyStatementRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/EmptyStatementRuleTest.java
new file mode 100644
index 0000000..4a82f39
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/EmptyStatementRuleTest.java
@@ -0,0 +1,39 @@
+/*
+ * 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 org.apache.flex.pmd.rules.maintanability;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class EmptyStatementRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("AbstractRowData.as", new ViolationPosition[]
+ {new ViolationPosition(101)}),
+ new ExpectedViolation("PngEncoder.as", new ViolationPosition[]
+ {new ViolationPosition(552)}),
+ new ExpectedViolation("com.adobe.ac.ncss.LongSwitch.as", new ViolationPosition[]
+ {new ViolationPosition(102)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new EmptyStatementRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/ExcessiveImportRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/ExcessiveImportRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/ExcessiveImportRuleTest.java
new file mode 100644
index 0000000..cb2cdbc
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/ExcessiveImportRuleTest.java
@@ -0,0 +1,39 @@
+/*
+ * 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 org.apache.flex.pmd.rules.maintanability;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class ExcessiveImportRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("cairngorm.LightController.as", new ViolationPosition[]
+ {new ViolationPosition(82)}),
+ new ExpectedViolation("cairngorm.FatController.as", new ViolationPosition[]
+ {new ViolationPosition(83)}),
+ new ExpectedViolation("com.adobe.ac.ncss.BigImporterModel.as", new ViolationPosition[]
+ {new ViolationPosition(42)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new ExcessiveImportRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/NonStaticConstantFieldRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/NonStaticConstantFieldRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/NonStaticConstantFieldRuleTest.java
new file mode 100644
index 0000000..799f791
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/NonStaticConstantFieldRuleTest.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 org.apache.flex.pmd.rules.maintanability;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class NonStaticConstantFieldRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("bug.FlexPMD115.as", new ViolationPosition[]
+ {new ViolationPosition(26),
+ new ViolationPosition(28)}),
+ new ExpectedViolation("AbstractRowData.as", new ViolationPosition[]
+ {new ViolationPosition(33),
+ new ViolationPosition(34),
+ new ViolationPosition(35),
+ new ViolationPosition(36),
+ new ViolationPosition(38)}),
+ new ExpectedViolation("Sorted.as", new ViolationPosition[]
+ {new ViolationPosition(31)}),
+ new ExpectedViolation("GenericType.as", new ViolationPosition[]
+ {new ViolationPosition(24)}),
+ new ExpectedViolation("com.adobe.ac.ncss.ArrayVO.as", new ViolationPosition[]
+ {new ViolationPosition(27)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new NonStaticConstantFieldRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/OnlyOneReturnRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/OnlyOneReturnRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/OnlyOneReturnRuleTest.java
new file mode 100644
index 0000000..9339fba
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/OnlyOneReturnRuleTest.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.flex.pmd.rules.maintanability;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+import java.util.List;
+
+public class OnlyOneReturnRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("PngEncoder.as", new ViolationPosition[]
+ {new ViolationPosition(172),
+ new ViolationPosition(592)}),
+ new ExpectedViolation("com.adobe.ac.AbstractRowData.as", new ViolationPosition[]
+ {new ViolationPosition(54)})};
+
+ }
+
+ @Override
+ protected List<String> getIgnoreFiles() {
+ final List<String> files = super.getIgnoreFiles();
+
+ files.add("bug.FlexPMD181.as");
+ return files;
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new OnlyOneReturnRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/ProtectedStaticMethodRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/ProtectedStaticMethodRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/ProtectedStaticMethodRuleTest.java
new file mode 100644
index 0000000..912743c
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/ProtectedStaticMethodRuleTest.java
@@ -0,0 +1,35 @@
+/*
+ * 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 org.apache.flex.pmd.rules.maintanability;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class ProtectedStaticMethodRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("Sorted.as", new ViolationPosition[]
+ {new ViolationPosition(48)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new ProtectedStaticMethodRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/ReferenceToVariableBindingFromItsInitializerRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/ReferenceToVariableBindingFromItsInitializerRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/ReferenceToVariableBindingFromItsInitializerRuleTest.java
new file mode 100644
index 0000000..d813747
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/ReferenceToVariableBindingFromItsInitializerRuleTest.java
@@ -0,0 +1,38 @@
+/*
+ * 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 org.apache.flex.pmd.rules.maintanability;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class ReferenceToVariableBindingFromItsInitializerRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("bug.FlexPMD115.as", new ViolationPosition[]
+ {new ViolationPosition(24),
+ new ViolationPosition(27),
+ new ViolationPosition(23),
+ new ViolationPosition(26)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new ReferenceToVariableBindingFromItsInitializerRule();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/TrueFalseConditionRuleTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/TrueFalseConditionRuleTest.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/TrueFalseConditionRuleTest.java
new file mode 100644
index 0000000..0062b06
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/test/java/org/apache/flex/pmd/rules/maintanability/TrueFalseConditionRuleTest.java
@@ -0,0 +1,53 @@
+/*
+ * 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 org.apache.flex.pmd.rules.maintanability;
+
+import org.apache.flex.pmd.rules.AbstractAstFlexRuleTest;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+
+public class TrueFalseConditionRuleTest extends AbstractAstFlexRuleTest {
+ @Override
+ protected ExpectedViolation[] getExpectedViolatingFiles() {
+ return new ExpectedViolation[]
+ {new ExpectedViolation("PngEncoder.as", new ViolationPosition[]
+ {new ViolationPosition(557),
+ new ViolationPosition(559),
+ new ViolationPosition(561),
+ new ViolationPosition(567)}),//3rdVialoation
+ new ExpectedViolation("Looping.as", new ViolationPosition[]
+ {new ViolationPosition(32),
+ new ViolationPosition(45),
+ new ViolationPosition(54),
+ new ViolationPosition(57)}),
+ new ExpectedViolation("RadonDataGrid.as", new ViolationPosition[]
+ {new ViolationPosition(51),
+ new ViolationPosition(182)}),
+ new ExpectedViolation("bug.FlexPMD181.as", new ViolationPosition[]
+ {new ViolationPosition(2210)}),
+ new ExpectedViolation("AbstractRowData.as", new ViolationPosition[]
+ {new ViolationPosition(94),
+ new ViolationPosition(101)}),
+ new ExpectedViolation("com.adobe.ac.AbstractRowData.as", new ViolationPosition[]
+ {new ViolationPosition(47)})};
+ }
+
+ @Override
+ protected AbstractFlexRule getRule() {
+ return new TrueFalseConditionRule();
+ }
+}
[12/24] git commit: [flex-utilities]
[refs/heads/feature/pmd-5.2-language-module] - Initial commit of the PMD
language module for Apache Flex
Posted by cd...@apache.org.
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/performance/DynamicFiltersUsedInPopup.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/performance/DynamicFiltersUsedInPopup.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/performance/DynamicFiltersUsedInPopup.java
new file mode 100644
index 0000000..e9e1c64
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/performance/DynamicFiltersUsedInPopup.java
@@ -0,0 +1,63 @@
+/*
+ * 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 org.apache.flex.pmd.rules.performance;
+
+import org.apache.flex.pmd.rules.core.AbstractRegexpBasedRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+/**
+ * @author xagnetti
+ */
+public class DynamicFiltersUsedInPopup extends AbstractRegexpBasedRule {
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractFlexRule#isConcernedByTheCurrentFile()
+ */
+ @Override
+ public final boolean isConcernedByTheCurrentFile() {
+ return getCurrentFile().getClassName().contains("Popup");
+ }
+
+ /*
+ * (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 ".*Filter.*";
+ }
+
+ /*
+ * (non-Javadoc)
+ * @seecom.adobe.ac.pmd.rules.core.AbstractRegexpBasedRule#
+ * isViolationDetectedOnThisMatchingLine(java.lang.String)
+ */
+ @Override
+ protected final boolean isViolationDetectedOnThisMatchingLine(final String line) {
+ return true;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/performance/HeavyConstructorRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/performance/HeavyConstructorRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/performance/HeavyConstructorRule.java
new file mode 100644
index 0000000..4994b41
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/performance/HeavyConstructorRule.java
@@ -0,0 +1,83 @@
+/*
+ * 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 org.apache.flex.pmd.rules.performance;
+
+import org.apache.flex.pmd.nodes.IFunction;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+import org.apache.flex.pmd.rules.core.thresholded.AbstractMaximizedAstFlexRule;
+
+/**
+ * @author xagnetti
+ */
+public class HeavyConstructorRule extends AbstractMaximizedAstFlexRule {
+ private IFunction currentConstructor = null;
+
+ /*
+ * (non-Javadoc)
+ * @seecom.adobe.ac.pmd.rules.core.thresholded.IThresholdedRule#
+ * getActualValueForTheCurrentViolation()
+ */
+ public final int getActualValueForTheCurrentViolation() {
+ return currentConstructor.getCyclomaticComplexity();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.thresholded.IThresholdedRule#getDefaultThreshold
+ * ()
+ */
+ public final int getDefaultThreshold() {
+ return 1;
+ }
+
+ /*
+ * (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#findViolationsFromConstructor
+ * (com.adobe.ac.pmd.nodes.IFunction)
+ */
+ @Override
+ protected final void findViolationsFromConstructor(final IFunction constructor) {
+ currentConstructor = constructor;
+ final int cyclomaticComplexity = constructor.getCyclomaticComplexity();
+ if (cyclomaticComplexity > getThreshold()) {
+ addViolation(constructor,
+ String.valueOf(cyclomaticComplexity));
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority()
+ */
+ @Override
+ protected final ViolationPriority getDefaultPriority() {
+ return ViolationPriority.HIGH;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/performance/RecursiveStyleManagerRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/performance/RecursiveStyleManagerRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/performance/RecursiveStyleManagerRule.java
new file mode 100644
index 0000000..68276e9
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/performance/RecursiveStyleManagerRule.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.flex.pmd.rules.performance;
+
+import org.apache.flex.pmd.parser.IParserNode;
+import org.apache.flex.pmd.rules.core.AbstractAstFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+/**
+ * @author xagnetti
+ */
+public final class RecursiveStyleManagerRule extends AbstractAstFlexRule {
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority()
+ */
+ @Override
+ protected ViolationPriority getDefaultPriority() {
+ return ViolationPriority.NORMAL;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#visitMethodCall(com.adobe
+ * .ac.pmd.parser.IParserNode)
+ */
+ @Override
+ protected void visitMethodCall(final IParserNode methodCallNode) {
+ final String methodName = methodCallNode.getChild(0).getStringValue();
+
+ if ("loadStyles".equals(methodName)
+ && (methodCallNode.getChild(1).numChildren() != 2 || "true".equals(methodCallNode.getChild(1)
+ .getChild(1)
+ .getStringValue()))) {
+ addViolation(methodCallNode);
+ }
+ super.visitMethodCall(methodCallNode);
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/performance/UseTraceFunctionRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/performance/UseTraceFunctionRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/performance/UseTraceFunctionRule.java
new file mode 100644
index 0000000..53f0b94
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/performance/UseTraceFunctionRule.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 org.apache.flex.pmd.rules.performance;
+
+import org.apache.flex.pmd.nodes.IFunction;
+import org.apache.flex.pmd.parser.IParserNode;
+import org.apache.flex.pmd.rules.core.AbstractPrimaryAstRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+/**
+ * @author xagnetti
+ */
+public class UseTraceFunctionRule extends AbstractPrimaryAstRule {
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractPrimaryAstRule#addViolation(com.adobe
+ * .ac.pmd.parser.IParserNode, com.adobe.ac.pmd.nodes.IFunction)
+ */
+ @Override
+ protected void addViolation(final IParserNode statement,
+ final IFunction function) {
+ addViolation(statement);
+ }
+
+ /*
+ * (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.AbstractPrimaryAstRule#getFirstPrimaryToFind()
+ */
+ @Override
+ protected String getFirstPrimaryToFind() {
+ return "trace";
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/security/AllowAllSecureDomainRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/security/AllowAllSecureDomainRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/security/AllowAllSecureDomainRule.java
new file mode 100644
index 0000000..4085646
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/security/AllowAllSecureDomainRule.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 org.apache.flex.pmd.rules.security;
+
+import org.apache.flex.pmd.rules.core.AbstractRegexpBasedRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+import java.util.regex.Matcher;
+
+/**
+ * @author xagnetti
+ */
+public class AllowAllSecureDomainRule extends AbstractRegexpBasedRule {
+ /*
+ * (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.HIGH;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.rules.core.AbstractRegexpBasedRule#getRegexp()
+ */
+ @Override
+ protected final String getRegexp() {
+ return "\\s*([a-zA-Z]+)\\.allowDomain\\s*\\(\\s*['\"]\\*['\"]\\s*\\).*";
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractRegexpBasedRule#isCurrentLineConcerned
+ * (java.lang.String)
+ */
+ @Override
+ protected boolean isCurrentLineConcerned(final String line) {
+ return line.contains("allowDomain");
+ }
+
+ /*
+ * (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);
+ final boolean result = false;
+
+ if (matcher.matches()) {
+ final String objectName = matcher.group(1).trim();
+
+ if (objectName == null) {
+ return false;
+ }
+
+ if (objectName.equalsIgnoreCase("Security")) {
+ return true;
+ }
+ }
+ return result;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/security/AllowInsecureDomainRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/security/AllowInsecureDomainRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/security/AllowInsecureDomainRule.java
new file mode 100644
index 0000000..9f51d98
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/security/AllowInsecureDomainRule.java
@@ -0,0 +1,83 @@
+/*
+ * 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 org.apache.flex.pmd.rules.security;
+
+import org.apache.flex.pmd.rules.core.AbstractRegexpBasedRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+import java.util.regex.Matcher;
+
+/**
+ * @author xagnetti
+ */
+public class AllowInsecureDomainRule extends AbstractRegexpBasedRule {
+ /*
+ * (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.HIGH;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.rules.core.AbstractRegexpBasedRule#getRegexp()
+ */
+ @Override
+ protected final String getRegexp() {
+ return ".*\\.allowInsecureDomain[ \\(]+.*";
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractRegexpBasedRule#isCurrentLineConcerned
+ * (java.lang.String)
+ */
+ @Override
+ protected boolean isCurrentLineConcerned(final String line) {
+ return line.contains("allowInsecureDomain");
+ }
+
+ /*
+ * (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);
+ final boolean result = false;
+
+ if (matcher.matches()) {
+ return true;
+ }
+ return result;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/security/ImportLoadBestPracticeRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/security/ImportLoadBestPracticeRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/security/ImportLoadBestPracticeRule.java
new file mode 100644
index 0000000..a3af42f
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/security/ImportLoadBestPracticeRule.java
@@ -0,0 +1,83 @@
+/*
+ * 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 org.apache.flex.pmd.rules.security;
+
+import org.apache.flex.pmd.rules.core.AbstractRegexpBasedRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+import java.util.regex.Matcher;
+
+/**
+ * @author xagnetti
+ */
+public class ImportLoadBestPracticeRule extends AbstractRegexpBasedRule {
+ /*
+ * (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 ".*(([,=]\\s*SecurityDomain\\.currentDomain)|(\\.loadBytes\\s?\\()).*";
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractRegexpBasedRule#isCurrentLineConcerned
+ * (java.lang.String)
+ */
+ @Override
+ protected boolean isCurrentLineConcerned(final String line) {
+ return line.contains("SecurityDomain.currentDomain")
+ || line.contains(".loadBytes");
+ }
+
+ /*
+ * (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);
+ final boolean result = false;
+
+ if (matcher.matches()) {
+ return true;
+ }
+ return result;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/security/InsecureExactSettingsRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/security/InsecureExactSettingsRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/security/InsecureExactSettingsRule.java
new file mode 100644
index 0000000..af727bb
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/security/InsecureExactSettingsRule.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 org.apache.flex.pmd.rules.security;
+
+import org.apache.flex.pmd.rules.core.AbstractRegexpBasedRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+import java.util.regex.Matcher;
+
+/**
+ * @author xagnetti
+ */
+public class InsecureExactSettingsRule extends AbstractRegexpBasedRule {
+ /*
+ * (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.HIGH;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.rules.core.AbstractRegexpBasedRule#getRegexp()
+ */
+ @Override
+ protected final String getRegexp() {
+ return ".*\\.exactSettings[ \\t=]+([a-zA-Z]+).*";
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractRegexpBasedRule#isCurrentLineConcerned
+ * (java.lang.String)
+ */
+ @Override
+ protected boolean isCurrentLineConcerned(final String line) {
+ return line.contains("exactSettings");
+ }
+
+ /*
+ * (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 (matcher.matches()) {
+ result = matcher.group(1).trim().equalsIgnoreCase("false");
+ }
+ return result;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/security/LSOSecureFalseRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/security/LSOSecureFalseRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/security/LSOSecureFalseRule.java
new file mode 100644
index 0000000..eac31b7
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/security/LSOSecureFalseRule.java
@@ -0,0 +1,86 @@
+/*
+ * 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 org.apache.flex.pmd.rules.security;
+
+import org.apache.flex.pmd.rules.core.AbstractRegexpBasedRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+import java.util.regex.Matcher;
+
+/**
+ * @author xagnetti
+ */
+public class LSOSecureFalseRule extends AbstractRegexpBasedRule {
+ /*
+ * (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 ".*\\.getLocal\\s*\\([^,]+\\,[^,]+\\,([A-Za-z ]+)\\).*";
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractRegexpBasedRule#isCurrentLineConcerned
+ * (java.lang.String)
+ */
+ @Override
+ protected boolean isCurrentLineConcerned(final String line) {
+ return line.contains("getLocal");
+ }
+
+ /*
+ * (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);
+
+ if (matcher.matches()) {
+ final String secureFlag = matcher.group(1).trim();
+
+ if (secureFlag.equalsIgnoreCase("false")) {
+ return true;
+ }
+
+ }
+ return false;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/security/LocalConnectionStarRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/security/LocalConnectionStarRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/security/LocalConnectionStarRule.java
new file mode 100644
index 0000000..6926e6e
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/security/LocalConnectionStarRule.java
@@ -0,0 +1,88 @@
+/*
+ * 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 org.apache.flex.pmd.rules.security;
+
+import org.apache.flex.pmd.rules.core.AbstractRegexpBasedRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+import java.util.regex.Matcher;
+
+/**
+ * @author xagnetti
+ */
+public class LocalConnectionStarRule extends AbstractRegexpBasedRule {
+ /*
+ * (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.HIGH;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.rules.core.AbstractRegexpBasedRule#getRegexp()
+ */
+ @Override
+ protected final String getRegexp() {
+ return ".*\\s([a-zA-Z0-9\\.\\-_]+)\\.allowDomain\\s*\\(\\s*['\"]\\*['\"]\\s*\\).*";
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractRegexpBasedRule#isCurrentLineConcerned
+ * (java.lang.String)
+ */
+ @Override
+ protected boolean isCurrentLineConcerned(final String line) {
+ return line.contains("allowDomain");
+ }
+
+ /*
+ * (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 (matcher.matches()) {
+ final String objectName = matcher.group(1).trim();
+
+ if (objectName.equalsIgnoreCase("Security")) {
+ return false;
+ }
+
+ result = true;
+ }
+ return result;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/sizing/TooLongFunctionRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/sizing/TooLongFunctionRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/sizing/TooLongFunctionRule.java
new file mode 100644
index 0000000..f76e75f
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/sizing/TooLongFunctionRule.java
@@ -0,0 +1,83 @@
+/*
+ * 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 org.apache.flex.pmd.rules.sizing;
+
+import org.apache.flex.pmd.nodes.utils.FunctionUtils;
+import org.apache.flex.pmd.parser.IParserNode;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+import org.apache.flex.pmd.rules.core.thresholded.AbstractMaximizedAstFlexRule;
+
+/**
+ * @author xagnetti
+ */
+public class TooLongFunctionRule extends AbstractMaximizedAstFlexRule {
+ public static final int DEFAULT_THRESHOLD = 20;
+ private int functionLength;
+
+ /*
+ * (non-Javadoc)
+ * @seecom.adobe.ac.pmd.rules.core.thresholded.IThresholdedRule#
+ * getActualValueForTheCurrentViolation()
+ */
+ public final int getActualValueForTheCurrentViolation() {
+ return functionLength;
+ }
+
+ /*
+ * (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#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 functionNode,
+ final FunctionType type) {
+ super.visitFunction(functionNode,
+ type);
+
+ final IParserNode block = functionNode.getChild(functionNode.numChildren() - 1);
+
+ if (block != null
+ && block.numChildren() != 0) {
+ functionLength = FunctionUtils.computeFunctionLength(getCurrentFile(),
+ block);
+ if (functionLength > getThreshold()) {
+ addViolation(getNameFromFunctionDeclaration(functionNode));
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/sizing/TooLongSwitchCaseRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/sizing/TooLongSwitchCaseRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/sizing/TooLongSwitchCaseRule.java
new file mode 100644
index 0000000..cbc9e58
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/sizing/TooLongSwitchCaseRule.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 org.apache.flex.pmd.rules.sizing;
+
+import org.apache.flex.pmd.parser.IParserNode;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+import org.apache.flex.pmd.rules.core.thresholded.AbstractMaximizedAstFlexRule;
+
+/**
+ * @author xagnetti
+ */
+public class TooLongSwitchCaseRule extends AbstractMaximizedAstFlexRule {
+ 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 2;
+ }
+
+ /*
+ * (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#visitSwitchCase(com.adobe
+ * .ac.pmd.parser.IParserNode)
+ */
+ @Override
+ protected final void visitSwitchCase(final IParserNode caseBlock) {
+ if (caseBlock.getLastChild() != null) {
+ length = caseBlock.getLastChild().getLine()
+ - caseBlock.getLine();
+ if (length > getThreshold()) {
+ addViolation(caseBlock);
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/sizing/TooManyFieldInVORule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/sizing/TooManyFieldInVORule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/sizing/TooManyFieldInVORule.java
new file mode 100644
index 0000000..4b3c1c5
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/sizing/TooManyFieldInVORule.java
@@ -0,0 +1,44 @@
+/*
+ * 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 org.apache.flex.pmd.rules.sizing;
+
+/**
+ * @author xagnetti
+ */
+public class TooManyFieldInVORule extends TooManyFieldsRule {
+ public static final int DEFAULT_THRESHOLD_FOR_VO = 15;
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.rules.sizing.TooManyFieldsRule#getDefaultThreshold()
+ */
+ @Override
+ public final int getDefaultThreshold() {
+ return DEFAULT_THRESHOLD_FOR_VO;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.sizing.TooManyFieldsRule#isConcernedByTheCurrentFile
+ * ()
+ */
+ @Override
+ public final boolean isConcernedByTheCurrentFile() {
+ return !super.isConcernedByTheCurrentFile();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/sizing/TooManyFieldsRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/sizing/TooManyFieldsRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/sizing/TooManyFieldsRule.java
new file mode 100644
index 0000000..25da29a
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/sizing/TooManyFieldsRule.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 org.apache.flex.pmd.rules.sizing;
+
+import org.apache.flex.pmd.nodes.IAttribute;
+import org.apache.flex.pmd.nodes.IClass;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+import org.apache.flex.pmd.rules.core.thresholded.AbstractMaximizedAstFlexRule;
+
+import java.util.List;
+
+/**
+ * @author xagnetti
+ */
+public class TooManyFieldsRule extends AbstractMaximizedAstFlexRule {
+ public static final int DEFAULT_THRESHOLD = 5;
+ private int attributesNb = 0;
+ private IClass classNode = null;
+
+ /*
+ * (non-Javadoc)
+ * @seecom.adobe.ac.pmd.rules.core.thresholded.IThresholdedRule#
+ * getActualValueForTheCurrentViolation()
+ */
+ public final int getActualValueForTheCurrentViolation() {
+ return attributesNb;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.thresholded.IThresholdedRule#getDefaultThreshold
+ * ()
+ */
+ public int getDefaultThreshold() {
+ return DEFAULT_THRESHOLD;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#isConcernedByTheCurrentFile
+ * ()
+ */
+ @Override
+ public boolean isConcernedByTheCurrentFile() {
+ return !getCurrentFile().getClassName().endsWith("VO.as");
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#findViolations(com.adobe
+ * .ac.pmd.nodes.IClass)
+ */
+ @Override
+ protected final void findViolations(final IClass classNodeToBeSet) {
+ classNode = classNodeToBeSet;
+ super.findViolations(classNodeToBeSet);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#findViolationsFromAttributes
+ * (java.util.List)
+ */
+ @Override
+ protected final void findViolationsFromAttributes(final List<IAttribute> attributes) {
+ attributesNb = attributes.size();
+
+ if (attributesNb > getThreshold()) {
+ addViolation(classNode);
+ }
+ }
+
+ /*
+ * (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/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/sizing/TooManyFunctionRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/sizing/TooManyFunctionRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/sizing/TooManyFunctionRule.java
new file mode 100644
index 0000000..89ba5b2
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/sizing/TooManyFunctionRule.java
@@ -0,0 +1,94 @@
+/*
+ * 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 org.apache.flex.pmd.rules.sizing;
+
+import org.apache.flex.pmd.nodes.IClass;
+import org.apache.flex.pmd.nodes.IFunction;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+import org.apache.flex.pmd.rules.core.thresholded.AbstractMaximizedAstFlexRule;
+
+import java.util.List;
+
+/**
+ * @author xagnetti
+ */
+public class TooManyFunctionRule extends AbstractMaximizedAstFlexRule {
+ public static final int DEFAULT_THRESHOLD = 10;
+ private IClass classNode = null;
+ private int functionNb;
+
+ /*
+ * (non-Javadoc)
+ * @seecom.adobe.ac.pmd.rules.core.thresholded.IThresholdedRule#
+ * getActualValueForTheCurrentViolation()
+ */
+ public final int getActualValueForTheCurrentViolation() {
+ return functionNb;
+ }
+
+ /*
+ * (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.AbstractAstFlexRule#findViolations(com.adobe
+ * .ac.pmd.nodes.IClass)
+ */
+ @Override
+ protected final void findViolations(final IClass classNodeToSet) {
+ functionNb = 0;
+ classNode = classNodeToSet;
+
+ super.findViolations(classNodeToSet);
+ }
+
+ /*
+ * (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 functionNode : functions) {
+ if (!functionNode.isGetter()
+ && !functionNode.isSetter() && functionNode != classNode.getConstructor()) {
+ functionNb++;
+ }
+ }
+ if (functionNb > getThreshold()) {
+ addViolation(classNode);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority()
+ */
+ @Override
+ protected final ViolationPriority getDefaultPriority() {
+ return ViolationPriority.HIGH;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/sizing/TooManyParametersRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/sizing/TooManyParametersRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/sizing/TooManyParametersRule.java
new file mode 100644
index 0000000..cd12275
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/sizing/TooManyParametersRule.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 org.apache.flex.pmd.rules.sizing;
+
+import org.apache.flex.pmd.parser.IParserNode;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+import org.apache.flex.pmd.rules.core.thresholded.AbstractMaximizedAstFlexRule;
+
+/**
+ * @author xagnetti
+ */
+public class TooManyParametersRule extends AbstractMaximizedAstFlexRule {
+ public static final int DEFAULT_THRESHOLD = 4;
+ private int paramsNb;
+
+ /*
+ * (non-Javadoc)
+ * @seecom.adobe.ac.pmd.rules.core.thresholded.IThresholdedRule#
+ * getActualValueForTheCurrentViolation()
+ */
+ public final int getActualValueForTheCurrentViolation() {
+ return paramsNb;
+ }
+
+ /*
+ * (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#getDefaultPriority()
+ */
+ @Override
+ protected final ViolationPriority getDefaultPriority() {
+ return ViolationPriority.LOW;
+ }
+
+ /*
+ * (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) {
+ super.visitFunction(ast,
+ type);
+
+ final IParserNode paramList = ast.getChild(2);
+
+ paramsNb = paramList.numChildren();
+
+ if (paramsNb > getThreshold()) {
+ addViolation(paramList);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/sizing/TooManyPublicRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/sizing/TooManyPublicRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/sizing/TooManyPublicRule.java
new file mode 100644
index 0000000..1bd5950
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/sizing/TooManyPublicRule.java
@@ -0,0 +1,109 @@
+/*
+ * 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 org.apache.flex.pmd.rules.sizing;
+
+import org.apache.flex.pmd.nodes.IAttribute;
+import org.apache.flex.pmd.nodes.IClass;
+import org.apache.flex.pmd.nodes.IFunction;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+import org.apache.flex.pmd.rules.core.thresholded.AbstractMaximizedAstFlexRule;
+
+import java.util.List;
+
+/**
+ * @author xagnetti
+ */
+public class TooManyPublicRule extends AbstractMaximizedAstFlexRule {
+ public static final int DEFAULT_THRESHOLD = 10;
+ private IFunction constructor;
+ private int publicCount;
+
+ /*
+ * (non-Javadoc)
+ * @seecom.adobe.ac.pmd.rules.core.thresholded.IThresholdedRule#
+ * getActualValueForTheCurrentViolation()
+ */
+ public final int getActualValueForTheCurrentViolation() {
+ return publicCount;
+ }
+
+ /*
+ * (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.AbstractAstFlexRule#findViolations(com.adobe
+ * .ac.pmd.nodes.IClass)
+ */
+ @Override
+ protected final void findViolations(final IClass classNode) {
+ publicCount = 0;
+ constructor = classNode.getConstructor();
+
+ super.findViolations(classNode);
+
+ if (publicCount > getThreshold()) {
+ addViolation(classNode);
+ }
+ }
+
+ /*
+ * (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.equals(constructor) && !function.isGetter() && !function.isSetter()) {
+ publicCount++;
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#findViolationsFromAttributes
+ * (java.util.List)
+ */
+ @Override
+ protected final void findViolationsFromAttributes(final List<IAttribute> variables) {
+ for (final IAttribute variable : variables) {
+ if (variable.isPublic()) {
+ publicCount++;
+ }
+ }
+ }
+
+ /*
+ * (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/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/style/BadFormatLoggerRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/style/BadFormatLoggerRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/style/BadFormatLoggerRule.java
new file mode 100644
index 0000000..c7127e5
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/style/BadFormatLoggerRule.java
@@ -0,0 +1,74 @@
+/*
+ * 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 org.apache.flex.pmd.rules.style;
+
+import org.apache.flex.pmd.nodes.IClass;
+import org.apache.flex.pmd.nodes.IField;
+import org.apache.flex.pmd.nodes.IVariable;
+import org.apache.flex.pmd.rules.core.AbstractAstFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+/**
+ * @author xagnetti
+ */
+public class BadFormatLoggerRule extends AbstractAstFlexRule {
+ private static final String CORRECT_LOGGER_NAME = "LOG";
+ private static final String LOGGER_INTERFACE = "ILogger";
+ private static final String MESSAGE_LOGGER_NAME_IS_NOT_LOG = "The logger name is not LOG";
+ private static final String MESSAGE_NOT_INITIALIZED = "The logger is not initialized";
+ private static final String MESSAGE_SHOULD_BE_CONSTANT = "A logger should be constant";
+
+ /*
+ * (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) {
+ for (final IVariable field : classNode.getAttributes()) {
+ if (field.getType().toString().equals(LOGGER_INTERFACE)) {
+ addViolation(field.getInternalNode(),
+ field.getInternalNode(),
+ MESSAGE_SHOULD_BE_CONSTANT);
+ }
+ }
+ for (final IField field : classNode.getConstants()) {
+ if (field.getType().toString().equals(LOGGER_INTERFACE)) {
+ if (!field.getName().equals(CORRECT_LOGGER_NAME)) {
+ addViolation(field.getInternalNode(),
+ field.getInternalNode(),
+ MESSAGE_LOGGER_NAME_IS_NOT_LOG);
+ }
+ if (field.getInitializationExpression() == null) {
+ addViolation(field.getInternalNode(),
+ field.getInternalNode(),
+ MESSAGE_NOT_INITIALIZED);
+ }
+ }
+ }
+ }
+
+ /*
+ * (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/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/style/ConstructorNonEmptyReturnTypeRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/style/ConstructorNonEmptyReturnTypeRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/style/ConstructorNonEmptyReturnTypeRule.java
new file mode 100644
index 0000000..b3d9428
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/style/ConstructorNonEmptyReturnTypeRule.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.flex.pmd.rules.style;
+
+import org.apache.flex.pmd.nodes.IFunction;
+import org.apache.flex.pmd.rules.core.AbstractAstFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+/**
+ * @author xagnetti
+ */
+public class ConstructorNonEmptyReturnTypeRule extends AbstractAstFlexRule {
+ /*
+ * (non-Javadoc)
+ * @see
+ * com.adobe.ac.pmd.rules.core.AbstractAstFlexRule#findViolationsFromConstructor
+ * (com.adobe.ac.pmd.nodes.IFunction)
+ */
+ @Override
+ protected final void findViolationsFromConstructor(final IFunction constructor) {
+ if (constructor.getReturnType() != null
+ && !"".equals(constructor.getReturnType().toString())) {
+ addViolation(constructor);
+ }
+ }
+
+ /*
+ * (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/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/style/CopyrightMissingRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/style/CopyrightMissingRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/style/CopyrightMissingRule.java
new file mode 100644
index 0000000..ff77df4
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/style/CopyrightMissingRule.java
@@ -0,0 +1,86 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+// 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 org.apache.flex.pmd.rules.style;
+
+import org.apache.flex.pmd.files.IAs3File;
+import org.apache.flex.pmd.files.IFlexFile;
+import org.apache.flex.pmd.files.IMxmlFile;
+import org.apache.flex.pmd.rules.IFlexViolation;
+import org.apache.flex.pmd.rules.core.AbstractFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author xagnetti
+ */
+public class CopyrightMissingRule extends AbstractFlexRule {
+ /*
+ * (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#findViolationsInCurrentFile()
+ */
+ @Override
+ protected final List<IFlexViolation> findViolationsInCurrentFile() {
+ final List<IFlexViolation> violations = new ArrayList<IFlexViolation>();
+ final IFlexFile currentFile = getCurrentFile();
+
+ if (currentFile.getLinesNb() == 1) {
+ addViolation(violations);
+ } else if (currentFile.getLinesNb() > 1) {
+ final String commentOpeningTag = currentFile.getCommentOpeningTag();
+ final String firstLine = currentFile.getLineAt(1);
+ final String secondLine = currentFile.getLineAt(2);
+
+ if (!firstLine.startsWith(commentOpeningTag)
+ && !(currentFile instanceof IMxmlFile && secondLine.contains(commentOpeningTag))
+ && !(currentFile instanceof IAs3File && firstLine.contains(currentFile.getSingleLineComment()))) {
+ addViolation(violations);
+ }
+ }
+
+ return violations;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see com.adobe.ac.pmd.rules.core.AbstractFlexRule#getDefaultPriority()
+ */
+ @Override
+ protected final ViolationPriority getDefaultPriority() {
+ return ViolationPriority.NORMAL;
+ }
+
+ private void addViolation(final List<IFlexViolation> violations) {
+ addViolation(violations,
+ new ViolationPosition(-1));
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/style/ImportFromSamePackageRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/style/ImportFromSamePackageRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/style/ImportFromSamePackageRule.java
new file mode 100644
index 0000000..2058a0e
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/style/ImportFromSamePackageRule.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 org.apache.flex.pmd.rules.style;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.flex.pmd.nodes.IPackage;
+import org.apache.flex.pmd.parser.IParserNode;
+import org.apache.flex.pmd.rules.core.AbstractAstFlexRule;
+import org.apache.flex.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/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/style/OverLongLineRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/style/OverLongLineRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/style/OverLongLineRule.java
new file mode 100644
index 0000000..5a15d6d
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/style/OverLongLineRule.java
@@ -0,0 +1,105 @@
+/*
+ * 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 org.apache.flex.pmd.rules.style;
+
+import org.apache.flex.pmd.files.IFlexFile;
+import org.apache.flex.pmd.rules.IFlexViolation;
+import org.apache.flex.pmd.rules.core.ViolationPosition;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+import org.apache.flex.pmd.rules.core.thresholded.AbstractMaximizedFlexRule;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @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/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/style/TabUsedAsIndentorRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/style/TabUsedAsIndentorRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/style/TabUsedAsIndentorRule.java
new file mode 100644
index 0000000..7e36887
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/style/TabUsedAsIndentorRule.java
@@ -0,0 +1,43 @@
+/*
+ * 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 org.apache.flex.pmd.rules.style;
+
+import org.apache.flex.pmd.rules.core.AbstractRegexpBasedRule;
+import org.apache.flex.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/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/switches/IdenticalSwitchCasesRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/switches/IdenticalSwitchCasesRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/switches/IdenticalSwitchCasesRule.java
new file mode 100644
index 0000000..b487342
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/switches/IdenticalSwitchCasesRule.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.flex.pmd.rules.switches;
+
+import org.apache.flex.pmd.parser.IParserNode;
+import org.apache.flex.pmd.rules.core.AbstractAstFlexRule;
+import org.apache.flex.pmd.rules.core.ViolationPriority;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+/**
+ * @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/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/switches/NestedSwitchRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/switches/NestedSwitchRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/switches/NestedSwitchRule.java
new file mode 100644
index 0000000..5227e72
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/switches/NestedSwitchRule.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.flex.pmd.rules.switches;
+
+import org.apache.flex.pmd.parser.IParserNode;
+import org.apache.flex.pmd.rules.core.AbstractAstFlexRule;
+import org.apache.flex.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/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/switches/NonBreakableSwitchCaseRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/switches/NonBreakableSwitchCaseRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/switches/NonBreakableSwitchCaseRule.java
new file mode 100644
index 0000000..2b9a6c4
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/switches/NonBreakableSwitchCaseRule.java
@@ -0,0 +1,37 @@
+/*
+ * 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 org.apache.flex.pmd.rules.switches;
+
+import org.apache.flex.pmd.parser.IParserNode;
+import org.apache.flex.pmd.rules.core.AbstractAstFlexRule;
+import org.apache.flex.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/ff722d6f/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/switches/SwitchStatementsShouldHaveDefaultRule.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/switches/SwitchStatementsShouldHaveDefaultRule.java b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/switches/SwitchStatementsShouldHaveDefaultRule.java
new file mode 100644
index 0000000..225a535
--- /dev/null
+++ b/FlexPMD/language-module/ruleset/ruleset-flex-basic/src/main/java/org/apache/flex/pmd/rules/switches/SwitchStatementsShouldHaveDefaultRule.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 org.apache.flex.pmd.rules.switches;
+
+import org.apache.flex.pmd.parser.IParserNode;
+import org.apache.flex.pmd.rules.core.AbstractAstFlexRule;
+import org.apache.flex.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;
+ }
+ }
+}
[24/24] git commit: [flex-utilities]
[refs/heads/feature/pmd-5.2-language-module] - Initial commit of the PMD
language module for Apache Flex
Posted by cd...@apache.org.
Initial commit of the PMD language module for Apache Flex
Project: http://git-wip-us.apache.org/repos/asf/flex-utilities/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-utilities/commit/ff722d6f
Tree: http://git-wip-us.apache.org/repos/asf/flex-utilities/tree/ff722d6f
Diff: http://git-wip-us.apache.org/repos/asf/flex-utilities/diff/ff722d6f
Branch: refs/heads/feature/pmd-5.2-language-module
Commit: ff722d6f57b15e1f1d3834efb6e44c7020fdd7e9
Parents: 3d7976a
Author: Christofer Dutz <ch...@codecentric.de>
Authored: Sat Mar 7 13:03:07 2015 +0100
Committer: Christofer Dutz <ch...@codecentric.de>
Committed: Sat Mar 7 13:03:08 2015 +0100
----------------------------------------------------------------------
.../language-module/parser/parser-api/pom.xml | 42 +
.../org/apache/flex/pmd/parser/IParserNode.java | 89 +
.../org/apache/flex/pmd/parser/KeyWords.java | 85 +
.../org/apache/flex/pmd/parser/NodeKind.java | 134 +
.../org/apache/flex/pmd/parser/Operators.java | 98 +
.../apache/flex/pmd/parser/ast/FlexNode.java | 9 +
.../org/apache/flex/pmd/parser/ast/Token.java | 72 +
.../parser/exceptions/NullTokenException.java | 31 +
.../pmd/parser/exceptions/TokenException.java | 30 +
.../exceptions/UnExpectedTokenException.java | 51 +
.../language-module/parser/parser-impl/pom.xml | 54 +
.../apache/flex/pmd/parser/impl/AS3Parser.java | 2037 +++++++++++++++
.../apache/flex/pmd/parser/impl/AS3Scanner.java | 695 ++++++
.../apache/flex/pmd/parser/impl/NestedNode.java | 200 ++
.../org/apache/flex/pmd/parser/impl/Node.java | 144 ++
.../parser/impl/AbstractAs3ParserTestBase.java | 74 +
.../parser/impl/AbstractStatementTestBase.java | 34 +
.../flex/pmd/parser/impl/NestedNodeTest.java | 77 +
.../apache/flex/pmd/parser/impl/NodeTest.java | 56 +
.../flex/pmd/parser/impl/TestAS3Parser.java | 73 +
.../flex/pmd/parser/impl/TestAS3Scanner.java | 322 +++
.../parser/impl/TestAS3ScannerWithFiles.java | 88 +
.../apache/flex/pmd/parser/impl/TestClass.java | 129 +
.../flex/pmd/parser/impl/TestClassContent.java | 285 +++
.../pmd/parser/impl/TestCompilationUnit.java | 84 +
.../pmd/parser/impl/TestConstStatement.java | 62 +
.../flex/pmd/parser/impl/TestDoStatement.java | 57 +
.../flex/pmd/parser/impl/TestE4xExpression.java | 44 +
.../pmd/parser/impl/TestEmptyStatement.java | 39 +
.../flex/pmd/parser/impl/TestExpression.java | 186 ++
.../flex/pmd/parser/impl/TestForStatement.java | 97 +
.../flex/pmd/parser/impl/TestIfStatement.java | 128 +
.../flex/pmd/parser/impl/TestInterface.java | 72 +
.../pmd/parser/impl/TestInterfaceContent.java | 88 +
.../pmd/parser/impl/TestPackageContent.java | 204 ++
.../pmd/parser/impl/TestPrimaryExpression.java | 102 +
.../pmd/parser/impl/TestReturnStatement.java | 65 +
.../pmd/parser/impl/TestSwitchStatement.java | 50 +
.../impl/TestTryCatchFinallyStatement.java | 54 +
.../pmd/parser/impl/TestUnaryExpression.java | 126 +
.../flex/pmd/parser/impl/TestVarStatement.java | 119 +
.../pmd/parser/impl/TestWhileStatement.java | 63 +
.../src/test/resources/examples/Enum.as | 84 +
.../src/test/resources/examples/FisheyeBase.as | 564 +++++
.../src/test/resources/examples/FlexPMD115.as | 22 +
.../src/test/resources/examples/FlexPMD195.as | 51 +
.../src/test/resources/examples/FlexPMD62.as | 35 +
.../src/test/resources/examples/FlexPMD98.as | 440 ++++
.../src/test/resources/examples/JPEGEncoder.as | 669 +++++
.../src/test/resources/examples/JPEGEncoder2.as | 671 +++++
.../toAS2/src/fw/data/request/ResultListener.as | 27 +
.../resources/examples/unformatted/IContext.as | 83 +
.../resources/examples/unformatted/Simple.as | 19 +
.../resources/examples/unformatted/Title.as | 32 +
FlexPMD/language-module/parser/pom.xml | 41 +
FlexPMD/language-module/pmd-flex/pom.xml | 55 +
.../org/apache/flex/pmd/FlexLanguageModule.java | 21 +
.../handler/Flex4LanguageVersionHandler.java | 25 +
.../flex/pmd/rule/FlexRuleChainVisitor.java | 25 +
.../apache/flex/pmd/rule/FlexRuleViolation.java | 23 +
.../flex/pmd/rule/FlexRuleViolationFactory.java | 28 +
.../org/apache/flex/pmd/rule/BasicTest.java | 16 +
.../org/apache/flex/pmd/rule/xml/simpletest.xml | 186 ++
FlexPMD/language-module/pom.xml | 132 +
FlexPMD/language-module/ruleset/pom.xml | 41 +
.../language-module/ruleset/ruleset-api/pom.xml | 58 +
.../org/apache/flex/pmd/files/IAs3File.java | 23 +
.../org/apache/flex/pmd/files/IFlexFile.java | 93 +
.../org/apache/flex/pmd/files/IMxmlFile.java | 42 +
.../flex/pmd/files/impl/AbstractFlexFile.java | 235 ++
.../org/apache/flex/pmd/files/impl/As3File.java | 79 +
.../apache/flex/pmd/files/impl/FileUtils.java | 268 ++
.../apache/flex/pmd/files/impl/MxmlFile.java | 291 +++
.../org/apache/flex/pmd/nodes/IAsDocHolder.java | 29 +
.../org/apache/flex/pmd/nodes/IAttribute.java | 23 +
.../java/org/apache/flex/pmd/nodes/IClass.java | 80 +
.../apache/flex/pmd/nodes/ICommentHolder.java | 31 +
.../org/apache/flex/pmd/nodes/IConstant.java | 23 +
.../java/org/apache/flex/pmd/nodes/IField.java | 27 +
.../flex/pmd/nodes/IFieldInitialization.java | 23 +
.../org/apache/flex/pmd/nodes/IFunction.java | 99 +
.../apache/flex/pmd/nodes/IIdentifierNode.java | 24 +
.../org/apache/flex/pmd/nodes/IMetaData.java | 46 +
.../flex/pmd/nodes/IMetaDataListHolder.java | 45 +
.../apache/flex/pmd/nodes/IModifiersHolder.java | 33 +
.../org/apache/flex/pmd/nodes/INamable.java | 27 +
.../org/apache/flex/pmd/nodes/INamableNode.java | 24 +
.../java/org/apache/flex/pmd/nodes/INode.java | 31 +
.../org/apache/flex/pmd/nodes/IPackage.java | 49 +
.../org/apache/flex/pmd/nodes/IParameter.java | 23 +
.../org/apache/flex/pmd/nodes/IVariable.java | 32 +
.../org/apache/flex/pmd/nodes/IVisible.java | 27 +
.../org/apache/flex/pmd/nodes/MetaData.java | 78 +
.../org/apache/flex/pmd/nodes/Modifier.java | 59 +
.../pmd/nodes/asdoc/impl/AsDocNodeBase.java | 39 +
.../pmd/nodes/asdoc/impl/ClassAsDocNode.java | 29 +
.../pmd/nodes/asdoc/impl/FunctionAsDocNode.java | 50 +
.../nodes/asdoc/impl/ParameterAsDocNode.java | 51 +
.../flex/pmd/nodes/impl/AbstractNode.java | 82 +
.../flex/pmd/nodes/impl/AttributeNode.java | 41 +
.../apache/flex/pmd/nodes/impl/ClassNode.java | 340 +++
.../flex/pmd/nodes/impl/ConstantNode.java | 41 +
.../pmd/nodes/impl/FieldInitializationNode.java | 49 +
.../apache/flex/pmd/nodes/impl/FieldNode.java | 83 +
.../apache/flex/pmd/nodes/impl/FormalNode.java | 49 +
.../flex/pmd/nodes/impl/FunctionNode.java | 367 +++
.../flex/pmd/nodes/impl/IdentifierNode.java | 58 +
.../flex/pmd/nodes/impl/MetaDataNode.java | 123 +
.../apache/flex/pmd/nodes/impl/NodeFactory.java | 45 +
.../apache/flex/pmd/nodes/impl/PackageNode.java | 146 ++
.../flex/pmd/nodes/impl/VariableNode.java | 182 ++
.../apache/flex/pmd/nodes/utils/AsDocUtils.java | 55 +
.../flex/pmd/nodes/utils/FunctionUtils.java | 48 +
.../apache/flex/pmd/rules/IFlexViolation.java | 52 +
.../pmd/rules/core/AbstractAstFlexRule.java | 970 ++++++++
.../rules/core/AbstractFlexMetaDataRule.java | 99 +
.../flex/pmd/rules/core/AbstractFlexRule.java | 326 +++
.../rules/core/AbstractForbiddenImportRule.java | 53 +
.../pmd/rules/core/AbstractPrimaryAstRule.java | 76 +
.../pmd/rules/core/AbstractRegexpBasedRule.java | 106 +
.../rules/core/AbstractXpathRelatedRule.java | 211 ++
.../flex/pmd/rules/core/IFlexAstRule.java | 27 +
.../apache/flex/pmd/rules/core/IFlexRule.java | 51 +
.../apache/flex/pmd/rules/core/Violation.java | 284 +++
.../flex/pmd/rules/core/ViolationPosition.java | 97 +
.../flex/pmd/rules/core/ViolationPriority.java | 42 +
.../AbstractMaximizedAstFlexRule.java | 43 +
.../thresholded/AbstractMaximizedFlexRule.java | 43 +
.../AbstractMaximizedRegexpBasedRule.java | 44 +
.../core/thresholded/IThresholdedRule.java | 44 +
.../ruleset/ruleset-flex-basic/pom.xml | 55 +
.../rules/architecture/MonkeyPatchingRule.java | 67 +
.../UseInternalClassOutsideApiClass.java | 113 +
.../ViewComponentReferencedInModelRule.java | 83 +
.../pmd/rules/asdocs/AbstractAsDocRule.java | 34 +
.../rules/asdocs/AttributeAsDocMissingRule.java | 49 +
.../pmd/rules/asdocs/ClassAsDocMissingRule.java | 56 +
.../rules/asdocs/MethodAsDocMissingRule.java | 49 +
.../pmd/rules/binding/BindingUtilsRule.java | 46 +
.../pmd/rules/binding/ChangeWatcherRule.java | 45 +
.../binding/TooLongBindingExpressionRule.java | 106 +
.../BadCairngormEventNameFormatRule.java | 105 +
.../cairngorm/BindableModelLocatorRule.java | 60 +
...rngormEventDispatcherCallExplicitlyRule.java | 71 +
.../pmd/rules/cairngorm/FatControllerRule.java | 88 +
...catorReferencedMoreThanOncePerClassRule.java | 49 +
...delLocatorOutsideTheMainApplicationRule.java | 67 +
.../rules/component/CallLaterDirectlyRule.java | 58 +
...teChildrenNumberInUpdateDisplayListRule.java | 61 +
.../pmd/rules/css/StyleBlockInMxmlRule.java | 63 +
.../css/UseCssInsteadOfEmbedMetaDataRule.java | 73 +
.../pmd/rules/empty/AbstractEmptyBlockRule.java | 35 +
.../rules/empty/EmptyCatchStatementRule.java | 49 +
.../flex/pmd/rules/empty/EmptyIfStmtRule.java | 49 +
.../rules/event/AbstractEventRelatedRule.java | 50 +
.../event/ConstructorDispatchingEventRule.java | 60 +
.../pmd/rules/event/DefaultEventNameRule.java | 49 +
.../event/DispatchHardCodedEventNameRule.java | 74 +
.../event/EventMissingCloneFunctionRule.java | 74 +
.../event/ListenForHardCodedEventNameRule.java | 74 +
.../event/PublicVariableInCustomEventRule.java | 52 +
.../rules/event/UnboundTypeInMetadataRule.java | 75 +
.../rules/event/UntypedEventMetadataRule.java | 64 +
.../flex/pmd/rules/flexunit/EmptyUnitTest.java | 93 +
.../pmd/rules/maintanability/AlertShowRule.java | 69 +
.../ArrayFieldWithNoArrayElementTypeRule.java | 85 +
.../AvoidProtectedFieldInFinalClassRule.java | 81 +
.../maintanability/AvoidUseOfAsKeywordRule.java | 42 +
.../AvoidUsingPublicStaticFieldRule.java | 54 +
.../AvoidUsingWithKeyWordRule.java | 53 +
.../ClassAndExtensionAreIdenticalRule.java | 61 +
.../rules/maintanability/DynamicClassRule.java | 60 +
.../maintanability/EmptyStatementRule.java | 46 +
.../maintanability/ExcessiveImportRule.java | 74 +
.../NonStaticConstantFieldRule.java | 54 +
.../rules/maintanability/OnlyOneReturnRule.java | 67 +
.../ProtectedStaticMethodRule.java | 50 +
...ToVariableBindingFromItsInitializerRule.java | 82 +
.../maintanability/TrueFalseConditionRule.java | 75 +
.../UselessOverridenFunctionRule.java | 73 +
.../AbstractUseForbiddenTypeRule.java | 105 +
.../forbiddentypes/UseDictionaryTypeRule.java | 44 +
.../forbiddentypes/UseGenericTypeRule.java | 46 +
.../forbiddentypes/UseObjectTypeRule.java | 84 +
.../multitouch/AvoidRollMouseEventRule.java | 64 +
.../pmd/rules/multitouch/AvoidTooltipRule.java | 63 +
.../AbstractMoreThanEntryPointInMxmlRule.java | 101 +
.../pmd/rules/mxml/CodeBehindInMxmlRule.java | 63 +
.../mxml/MoreThanOneEntryPointInMxmlRule.java | 44 +
.../mxml/MoreThanTwoEntryPointsInMxmlRule.java | 44 +
.../mxml/OnlyOneScriptBlockPerMxmlRule.java | 89 +
.../pmd/rules/mxml/StaticMethodInMxmlRule.java | 61 +
.../pmd/rules/mxml/TooLongScriptBlockRule.java | 92 +
.../pmd/rules/mxml/TooManyStatesInMxmlRule.java | 135 +
.../BooleanAttributeShouldContainIsHasRule.java | 65 +
.../rules/naming/CapitalizeConstantsRule.java | 45 +
.../pmd/rules/naming/IncorrectClassCase.java | 52 +
.../naming/IncorrectEventHandlerNameRule.java | 67 +
.../pmd/rules/naming/InterfaceNamingRule.java | 37 +
.../flex/pmd/rules/naming/PackageCaseRule.java | 69 +
.../PropertyHiddenByLocalVariableRule.java | 67 +
.../rules/naming/TooLongFunctionNameRule.java | 49 +
.../pmd/rules/naming/TooShortVariableRule.java | 128 +
.../VariableNameEndingWithNumericRule.java | 97 +
.../rules/naming/WronglyNamedVariableRule.java | 109 +
.../ParameterizedRegExpBasedRule.java | 72 +
.../rules/parsley/InaccessibleMetaDataRule.java | 85 +
.../MessageInterceptorSignatureRule.java | 81 +
.../parsley/MismatchedManagedEventRule.java | 78 +
.../rules/parsley/MisplacedMetaDataRule.java | 102 +
...edundantMessageHandlerTypeAttributeRule.java | 89 +
.../parsley/RedundantMethodAttributeRule.java | 72 +
.../parsley/UnknownMetaDataAttributeRule.java | 71 +
.../pmd/rules/parsley/utils/MetaDataTag.java | 95 +
.../rules/parsley/utils/ParsleyMetaData.java | 266 ++
.../AbstractAvoidNodeInLoopRule.java | 74 +
.../performance/AvoidDeclarationInLoopRule.java | 34 +
.../AvoidInstanciationInLoopRule.java | 41 +
.../performance/AvoidUsingMathCeilRule.java | 69 +
.../performance/AvoidUsingMathFloorRule.java | 69 +
.../performance/AvoidUsingMathRoundRule.java | 69 +
.../rules/performance/BindableClassRule.java | 61 +
.../performance/CreationPolicySetToAllRule.java | 65 +
.../performance/CyclomaticComplexityRule.java | 71 +
.../rules/performance/DeeplyNestedIfRule.java | 113 +
.../performance/DynamicFiltersUsedInPopup.java | 63 +
.../rules/performance/HeavyConstructorRule.java | 83 +
.../performance/RecursiveStyleManagerRule.java | 54 +
.../rules/performance/UseTraceFunctionRule.java | 58 +
.../security/AllowAllSecureDomainRule.java | 91 +
.../rules/security/AllowInsecureDomainRule.java | 83 +
.../security/ImportLoadBestPracticeRule.java | 83 +
.../security/InsecureExactSettingsRule.java | 82 +
.../pmd/rules/security/LSOSecureFalseRule.java | 86 +
.../rules/security/LocalConnectionStarRule.java | 88 +
.../pmd/rules/sizing/TooLongFunctionRule.java | 83 +
.../pmd/rules/sizing/TooLongSwitchCaseRule.java | 73 +
.../pmd/rules/sizing/TooManyFieldInVORule.java | 44 +
.../pmd/rules/sizing/TooManyFieldsRule.java | 99 +
.../pmd/rules/sizing/TooManyFunctionRule.java | 94 +
.../pmd/rules/sizing/TooManyParametersRule.java | 79 +
.../pmd/rules/sizing/TooManyPublicRule.java | 109 +
.../pmd/rules/style/BadFormatLoggerRule.java | 74 +
.../ConstructorNonEmptyReturnTypeRule.java | 49 +
.../pmd/rules/style/CopyrightMissingRule.java | 86 +
.../rules/style/ImportFromSamePackageRule.java | 55 +
.../flex/pmd/rules/style/OverLongLineRule.java | 105 +
.../pmd/rules/style/TabUsedAsIndentorRule.java | 43 +
.../switches/IdenticalSwitchCasesRule.java | 65 +
.../pmd/rules/switches/NestedSwitchRule.java | 54 +
.../switches/NonBreakableSwitchCaseRule.java | 37 +
.../SwitchStatementsShouldHaveDefaultRule.java | 69 +
.../TooFewBrancheInSwitchStatementRule.java | 121 +
.../unused/AbstractUnusedVariableRule.java | 112 +
.../rules/unused/EmptyPrivateMethodRule.java | 37 +
.../flex/pmd/rules/unused/UnusedFieldRule.java | 116 +
.../rules/unused/UnusedLocalVariableRule.java | 71 +
.../pmd/rules/unused/UnusedParameterRule.java | 202 ++
.../rules/unused/UnusedPrivateMethodRule.java | 151 ++
.../resources/rulesets/flex/architecture.xml | 120 +
.../src/main/resources/rulesets/flex/asdocs.xml | 49 +
.../main/resources/rulesets/flex/basic_mxml.xml | 66 +
.../main/resources/rulesets/flex/binding.xml | 71 +
.../main/resources/rulesets/flex/cairngorm.xml | 135 +
.../main/resources/rulesets/flex/component.xml | 44 +
.../src/main/resources/rulesets/flex/css.xml | 42 +
.../src/main/resources/rulesets/flex/empty.xml | 67 +
.../src/main/resources/rulesets/flex/event.xml | 148 ++
.../main/resources/rulesets/flex/flexunit.xml | 35 +
.../resources/rulesets/flex/indentation.xml | 32 +
.../resources/rulesets/flex/maintanability.xml | 237 ++
.../main/resources/rulesets/flex/multitouch.xml | 40 +
.../src/main/resources/rulesets/flex/naming.xml | 163 ++
.../main/resources/rulesets/flex/parsley.xml | 147 ++
.../resources/rulesets/flex/performance.xml | 115 +
.../main/resources/rulesets/flex/security.xml | 87 +
.../src/main/resources/rulesets/flex/sizing.xml | 179 ++
.../src/main/resources/rulesets/flex/style.xml | 87 +
.../main/resources/rulesets/flex/switches.xml | 112 +
.../src/main/resources/rulesets/flex/unused.xml | 83 +
.../flex/pmd/rules/AbstractAstFlexRuleTest.java | 57 +
.../flex/pmd/rules/AbstractFlexRuleTest.java | 223 ++
.../pmd/rules/AbstractRegExpBasedRuleTest.java | 65 +
.../apache/flex/pmd/rules/FlexPmdTestBase.java | 69 +
.../flex/pmd/rules/ResourcesManagerTest.java | 90 +
.../architecture/MonkeyPatchingRuleTest.java | 35 +
.../UseInternalClassOutsideApiClassTest.java | 45 +
.../ViewComponentReferencedInModelRuleTest.java | 53 +
.../pmd/rules/asdocs/AbstractAsDocRuleTest.java | 58 +
.../asdocs/AttributeAsDocMissingRuleTest.java | 34 +
.../rules/asdocs/ClassAsDocMissingRuleTest.java | 34 +
.../asdocs/MethodAsDocMissingRuleTest.java | 36 +
.../pmd/rules/binding/BindingUtilsRuleTest.java | 35 +
.../rules/binding/ChangeWatcherRuleTest.java | 35 +
.../TooLongBindingExpressionRuleTest.java | 51 +
.../BadCairngormEventNameFormatRuleTest.java | 38 +
.../cairngorm/BindableModelLocatorRuleTest.java | 35 +
...rmEventDispatcherCallExplicitlyRuleTest.java | 36 +
.../rules/cairngorm/FatControllerRuleTest.java | 35 +
...rReferencedMoreThanOncePerClassRuleTest.java | 35 +
...ocatorOutsideTheMainApplicationRuleTest.java | 55 +
.../component/CallLaterDirectlyRuleTest.java | 36 +
...ildrenNumberInUpdateDisplayListRuleTest.java | 38 +
.../pmd/rules/css/StyleBlockInMxmlRuleTest.java | 61 +
.../UseCssInsteadOfEmbedMetaDataRuleTest.java | 35 +
.../empty/EmptyCatchStatementRuleTest.java | 35 +
.../pmd/rules/empty/EmptyIfStmtRuleTest.java | 46 +
.../ConstructorDispatchingEventRuleTest.java | 35 +
.../rules/event/DefaultEventNameRuleTest.java | 35 +
.../DispatchHardCodedEventNameRuleTest.java | 56 +
.../EventMissingCloneFunctionRuleTest.java | 38 +
.../ListenForHardCodedEventNameRuleTest.java | 52 +
.../PublicVariableInCustomEventRuleTest.java | 38 +
.../event/UnboundTypeInMetadataRuleTest.java | 37 +
.../event/UntypedEventMetadataRuleTest.java | 35 +
.../pmd/rules/flexunit/EmptyUnitTestTest.java | 38 +
.../rules/maintanability/AlertShowRuleTest.java | 44 +
...rrayFieldWithNoArrayElementTypeRuleTest.java | 37 +
...AvoidProtectedFieldInFinalClassRuleTest.java | 36 +
.../AvoidUseOfAsKeywordRuleTest.java | 74 +
.../AvoidUsingPublicStaticFieldRuleTest.java | 37 +
.../AvoidUsingWithKeyWordRuleTest.java | 35 +
.../ClassAndExtensionAreIdenticalRuleTest.java | 35 +
.../maintanability/DynamicClassRuleTest.java | 35 +
.../maintanability/EmptyStatementRuleTest.java | 39 +
.../maintanability/ExcessiveImportRuleTest.java | 39 +
.../NonStaticConstantFieldRuleTest.java | 48 +
.../maintanability/OnlyOneReturnRuleTest.java | 49 +
.../ProtectedStaticMethodRuleTest.java | 35 +
...riableBindingFromItsInitializerRuleTest.java | 38 +
.../TrueFalseConditionRuleTest.java | 53 +
.../UselessOverridenFunctionRuleTest.java | 37 +
.../UseDictionaryTypeRuleTest.java | 36 +
.../forbiddenttypes/UseGenericTypeRuleTest.java | 50 +
.../forbiddenttypes/UseObjectTypeRuleTest.java | 51 +
.../multitouch/AvoidRollMouseEventRuleTest.java | 54 +
.../rules/multitouch/AvoidTooltipRuleTest.java | 50 +
...bstractMoreThanEntryPointInMxmlRuleTest.java | 34 +
.../rules/mxml/CodeBehindInMxmlRuleTest.java | 50 +
.../MoreThanOneEntryPointInMxmlRuleTest.java | 39 +
.../MoreThanTwoEntryPointsInMxmlRuleTest.java | 39 +
.../mxml/OnlyOneScriptBlockPerMxmlRuleTest.java | 37 +
.../rules/mxml/StaticMethodInMxmlRuleTest.java | 35 +
.../rules/mxml/TooLongScriptBlockRuleTest.java | 42 +
.../rules/mxml/TooManyStatesInMxmlRuleTest.java | 35 +
...leanAttributeShouldContainIsHasRuleTest.java | 33 +
.../naming/CapitalizeConstantsRuleTest.java | 43 +
.../rules/naming/IncorrectClassCaseTest.java | 35 +
.../IncorrectEventHandlerNameRuleTest.java | 44 +
.../rules/naming/InterfaceNamingRuleTest.java | 40 +
.../pmd/rules/naming/PackageCaseRuleTest.java | 45 +
.../PropertyHiddenByLocalVariableRuleTest.java | 35 +
.../naming/TooLongFunctionNameRuleTest.java | 35 +
.../rules/naming/TooShortVariableRuleTest.java | 64 +
.../VariableNameEndingWithNumericRuleTest.java | 75 +
.../naming/WronglyNamedVariableRuleTest.java | 67 +
.../ParameterizedRegExpBasedRuleTest.java | 39 +
...rizedRegExpBasedRuleWithEmptyRegexpTest.java | 33 +
.../parsley/InaccessibleMetaDataRuleTest.java | 40 +
.../MessageInterceptorSignatureRuleTest.java | 37 +
.../parsley/MismatchedManagedEventRuleTest.java | 35 +
.../parsley/MisplacedMetaDataRuleTest.java | 64 +
...dantMessageHandlerTypeAttributeRuleTest.java | 35 +
.../RedundantMethodAttributeRuleTest.java | 35 +
.../UnknownMetaDataAttributeRuleTest.java | 37 +
.../AvoidDeclarationInLoopRuleTest.java | 97 +
.../AvoidInstanciationInLoopRuleTest.java | 47 +
.../performance/AvoidUsingMathCeilRuleTest.java | 33 +
.../AvoidUsingMathFloorRuleTest.java | 36 +
.../AvoidUsingMathRoundRuleTest.java | 35 +
.../performance/BindableClassRuleTest.java | 39 +
.../CreationPolicySetToAllRuleTest.java | 48 +
.../CyclomaticComplexityRuleTest.java | 42 +
.../performance/DeeplyNestedIfRuleTest.java | 43 +
.../DynamicFiltersUsedInPopupTest.java | 55 +
.../performance/HeavyConstructorRuleTest.java | 43 +
.../RecursiveStyleManagerRuleTest.java | 36 +
.../performance/UseTraceFunctionRuleTest.java | 40 +
.../security/AllowAllSecureDomainRuleTest.java | 77 +
.../security/AllowInsecureDomainRuleTest.java | 50 +
.../ImportLoadBestPracticeRuleTest.java | 47 +
.../security/InsecureExactSettingsRuleTest.java | 50 +
.../rules/security/LSOSecureFalseRuleTest.java | 54 +
.../security/LocalConnectionStarRuleTest.java | 52 +
.../rules/sizing/TooLongFunctionRuleTest.java | 51 +
.../rules/sizing/TooLongSwitchCaseRuleTest.java | 44 +
.../rules/sizing/TooManyFieldInVORuleTest.java | 35 +
.../pmd/rules/sizing/TooManyFieldsRuleTest.java | 41 +
.../rules/sizing/TooManyFunctionRuleTest.java | 39 +
.../rules/sizing/TooManyParametersRuleTest.java | 41 +
.../pmd/rules/sizing/TooManyPublicRuleTest.java | 39 +
.../rules/style/BadFormatLoggerRuleTest.java | 38 +
.../ConstructorNonEmptyReturnTypeRuleTest.java | 35 +
.../rules/style/CopyrightMissingRuleTest.java | 39 +
.../style/ImportFromSamePackageRuleTest.java | 35 +
.../pmd/rules/style/OverLongLineRuleTest.java | 52 +
.../rules/style/TabUsedAsIndentorRuleTest.java | 86 +
.../IdenticalSwitchCasesRuleTest.java | 36 +
.../rules/switchrules/NestedSwitchRuleTest.java | 38 +
.../NonBreakableSwitchCaseRuleTest.java | 36 +
...itchStatementsShouldHaveDefaultRuleTest.java | 40 +
.../TooFewBrancheInSwitchStatementRuleTest.java | 38 +
.../unused/EmptyPrivateMethodRuleTest.java | 46 +
.../pmd/rules/unused/UnusedFieldRuleTest.java | 41 +
.../unused/UnusedLocalVariableRuleTest.java | 83 +
.../rules/unused/UnusedParameterRuleTest.java | 52 +
.../unused/UnusedPrivateMethodRuleTest.java | 46 +
.../src/test/resources/test/AbstractRowData.as | 136 +
.../test/resources/test/AbstractRowData.mxml | 44 +
.../src/test/resources/test/BadComponent.as | 43 +
.../src/test/resources/test/Color.as | 29 +
.../src/test/resources/test/DefaultNameEvent.as | 36 +
.../resources/test/DeleteButtonRenderer.mxml | 101 +
.../src/test/resources/test/ErrorToltipSkin.as | 317 +++
.../src/test/resources/test/GenericType.as | 37 +
.../src/test/resources/test/GoodComponent.as | 51 +
.../test/LinkButtonExample_Exception.mxml | 38 +
.../src/test/resources/test/Looping.as | 68 +
.../src/test/resources/test/Main.mxml | 45 +
.../resources/test/MainWithModelLocator.mxml | 42 +
.../resources/test/MainWithNoCopyright.mxml | 4 +
.../src/test/resources/test/PngEncoder.as | 617 +++++
.../src/test/resources/test/RadonDataGrid.as | 200 ++
.../src/test/resources/test/Responder.as | 36 +
.../src/test/resources/test/Simple.as | 1 +
.../src/test/resources/test/SkinStyles.as | 65 +
.../src/test/resources/test/Sorted.as | 62 +
.../src/test/resources/test/Title.as | 33 +
.../src/test/resources/test/UnboundMetadata.as | 41 +
.../src/test/resources/test/WorkEvent.as | 205 ++
.../test/resources/test/asDocs/EmptyClass.as | 38 +
.../resources/test/asDocs/EmptyWithDocClass.as | 51 +
.../src/test/resources/test/bug/Duane.mxml | 154 ++
.../src/test/resources/test/bug/FlexPMD115.as | 30 +
.../test/resources/test/bug/FlexPMD141a.mxml | 32 +
.../test/resources/test/bug/FlexPMD141b.mxml | 34 +
.../src/test/resources/test/bug/FlexPMD157.as | 33 +
.../src/test/resources/test/bug/FlexPMD173.as | 40 +
.../src/test/resources/test/bug/FlexPMD181.as | 2344 ++++++++++++++++++
.../src/test/resources/test/bug/FlexPMD232.as | 36 +
.../test/resources/test/bug/FlexPMD233a.mxml | 91 +
.../test/resources/test/bug/FlexPMD233b.mxml | 300 +++
.../src/test/resources/test/bug/FlexPMD61.as | 42 +
.../src/test/resources/test/bug/FlexPMD62.as | 35 +
.../src/test/resources/test/bug/FlexPMD88.as | 41 +
.../src/test/resources/test/bug/FlexPMD97.as | 31 +
.../src/test/resources/test/bug/Nico.as | 30 +
.../src/test/resources/test/bug/Security.as | 36 +
.../test/cairngorm/BindableModelLocator.as | 23 +
.../resources/test/cairngorm/FatController.as | 183 ++
.../resources/test/cairngorm/LightController.as | 201 ++
.../test/cairngorm/NonBindableModelLocator.as | 54 +
.../cairngorm/events/CorrectConstantEvent.as | 45 +
.../cairngorm/events/CorrectConstructorEvent.as | 38 +
.../cairngorm/events/UncorrectConstantEvent.as | 40 +
.../events/UncorrectConstructorEvent.as | 38 +
.../test/com/adobe/ac/AbstractRowData.as | 118 +
.../src/test/resources/test/com/adobe/ac/foo.as | 22 +
.../resources/test/com/adobe/ac/ncss/ArrayVO.as | 46 +
.../test/com/adobe/ac/ncss/BigImporterModel.as | 78 +
.../test/com/adobe/ac/ncss/BigModel.as | 90 +
.../test/com/adobe/ac/ncss/ConfigProxy.as | 50 +
.../test/com/adobe/ac/ncss/LongSwitch.as | 132 +
.../com/adobe/ac/ncss/MyCairngormCommand.as | 30 +
.../test/com/adobe/ac/ncss/NestedSwitch.as | 59 +
.../test/com/adobe/ac/ncss/SearchBarEvent.as | 34 +
.../test/com/adobe/ac/ncss/VoidConstructor.as | 37 +
.../adobe/ac/ncss/event/DynamicCustomEvent.as | 35 +
.../com/adobe/ac/ncss/event/FirstCustomEvent.as | 30 +
.../adobe/ac/ncss/event/SecondCustomEvent.as | 28 +
.../com/adobe/ac/ncss/mxml/IterationsList.mxml | 90 +
.../com/adobe/ac/ncss/mxml/IterationsList2.mxml | 44 +
.../com/adobe/ac/ncss/mxml/NestedComponent.mxml | 43 +
.../adobe/cairngorm/work/SequenceWorkFlow.as | 19 +
.../src/test/resources/test/empty/Empty.as | 18 +
.../src/test/resources/test/empty/Empty.mxml | 18 +
.../src/test/resources/test/filters/MyPopup.as | 28 +
.../test/resources/test/filters/MyPopup.mxml | 32 +
.../test/resources/test/flexpmd114/a/Test.as | 39 +
.../test/resources/test/flexpmd114/b/Test.as | 35 +
.../test/resources/test/flexpmd114/c/Test.as | 35 +
.../test/resources/test/flexunit/RaoulTest.as | 69 +
.../test/resources/test/flexunit/RulesetTest.as | 62 +
.../test/resources/test/fu/main/flex/Main.mxml | 22 +
.../fu/main/flex/TestRunnerApplication.mxml | 50 +
.../test/resources/test/fu/test/flex/MySuite.as | 26 +
.../test/resources/test/fu/test/flex/MyTest.as | 46 +
.../test/functional/FunctionalClient.as | 29 +
.../functional/func1/api/Func1ExposedClass.as | 29 +
.../func1/restricted/Func1RestrictedClass.as | 29 +
.../functional/func2/api/Func2ExposedClass.as | 28 +
.../func2/restricted/Func2RestrictedClass.as | 28 +
.../resources/test/mx/controls/DateChooser2.as | 25 +
.../org/as3commons/concurrency/thread/Color.as | 25 +
.../test/parsley/InaccessibleMetaData.as | 53 +
.../InaccessibleMetaDataInternalClass.as | 25 +
.../test/parsley/MessageInterceptorSignature.as | 47 +
.../test/parsley/MismatchedManagedEvent.as | 28 +
.../resources/test/parsley/MisplacedMetaData.as | 65 +
.../RedundantMessageHandlerTypeAttribute.as | 35 +
.../test/parsley/RedundantMethodAttribute.as | 35 +
.../test/parsley/UnknownMetaDataAttribute.as | 32 +
.../resources/test/pseudo/look/IEditLook.as | 24 +
.../test/resources/test/schedule_internal.as | 22 +
.../test/src/fw/data/request/ResultListener.as | 27 +
FlexPMD/language-module/utils/pom.xml | 42 +
.../org/apache/flex/pmd/utils/FileUtils.java | 164 ++
.../org/apache/flex/pmd/utils/FlexFilter.java | 41 +
.../org/apache/flex/pmd/utils/RegexUtils.java | 16 +
.../apache/flex/pmd/utils/StackTraceUtils.java | 51 +
510 files changed, 42238 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-api/pom.xml
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/parser/parser-api/pom.xml b/FlexPMD/language-module/parser/parser-api/pom.xml
new file mode 100644
index 0000000..86bd549
--- /dev/null
+++ b/FlexPMD/language-module/parser/parser-api/pom.xml
@@ -0,0 +1,42 @@
+<!--
+
+ 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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.flex.pmd.parser</groupId>
+ <artifactId>parser</artifactId>
+ <version>2.0.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>parser-api</artifactId>
+ <version>2.0.0-SNAPSHOT</version>
+ <packaging>jar</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>net.sourceforge.pmd</groupId>
+ <artifactId>pmd-core</artifactId>
+ <version>${pmd.version}</version>
+ </dependency>
+ </dependencies>
+
+</project>
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-api/src/main/java/org/apache/flex/pmd/parser/IParserNode.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/parser/parser-api/src/main/java/org/apache/flex/pmd/parser/IParserNode.java b/FlexPMD/language-module/parser/parser-api/src/main/java/org/apache/flex/pmd/parser/IParserNode.java
new file mode 100644
index 0000000..2141367
--- /dev/null
+++ b/FlexPMD/language-module/parser/parser-api/src/main/java/org/apache/flex/pmd/parser/IParserNode.java
@@ -0,0 +1,89 @@
+/*
+ * 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 org.apache.flex.pmd.parser;
+
+import java.util.List;
+
+/**
+ * @author xagnetti
+ */
+public interface IParserNode {
+ /**
+ * @return the cyclomatic complexity of the current node
+ */
+ int computeCyclomaticComplexity();
+
+ /**
+ * @param type
+ * @return count recursivly the number of children which are of type "type"
+ */
+ int countNodeFromType(final NodeKind type);
+
+ /**
+ * @param names
+ * @return the list of IParserNode which names is contained in the given
+ * names array
+ */
+ List<IParserNode> findPrimaryStatementsFromNameInChildren(final String[] names);
+
+ /**
+ * @param index
+ * @return the indexth child
+ */
+ IParserNode getChild(final int index);
+
+ /**
+ * @return the entire list of chilren
+ */
+ List<IParserNode> getChildren();
+
+ /**
+ * @return node's column
+ */
+ int getColumn();
+
+ /**
+ * @return node's type
+ */
+ NodeKind getId();
+
+ /**
+ * @return the node's last child
+ */
+ IParserNode getLastChild();
+
+ /**
+ * @return nodes's line
+ */
+ int getLine();
+
+ /**
+ * @return node's string value
+ */
+ String getStringValue();
+
+ /**
+ * @param expectedType
+ * @return true if the node's type is identical to the given name
+ */
+ boolean is(final NodeKind expectedType); // NOPMD
+
+ /**
+ * @return the children number
+ */
+ int numChildren();
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-api/src/main/java/org/apache/flex/pmd/parser/KeyWords.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/parser/parser-api/src/main/java/org/apache/flex/pmd/parser/KeyWords.java b/FlexPMD/language-module/parser/parser-api/src/main/java/org/apache/flex/pmd/parser/KeyWords.java
new file mode 100644
index 0000000..83de51b
--- /dev/null
+++ b/FlexPMD/language-module/parser/parser-api/src/main/java/org/apache/flex/pmd/parser/KeyWords.java
@@ -0,0 +1,85 @@
+/*
+ * 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 org.apache.flex.pmd.parser;
+
+/**
+ * @author xagnetti
+ */
+public enum KeyWords {
+ AS("as"),
+ CASE("case"),
+ CATCH("catch"),
+ CLASS("class"),
+ CONST("const"),
+ DEFAULT("default"),
+ DELETE("delete"),
+ DO("do"),
+ DYNAMIC("dynamic"),
+ EACH("each"),
+ ELSE("else"),
+ EOF("__END__"),
+ EXTENDS("extends"),
+ FINAL("final"),
+ FINALLY("finally"),
+ FOR("for"),
+ FUNCTION("function"),
+ GET("get"),
+ IF("if"),
+ IMPLEMENTS("implements"),
+ IMPORT("import"),
+ IN("in"),
+ INCLUDE("include"),
+ INCLUDE_AS2("#include"),
+ INSTANCE_OF("instanceof"),
+ INTERFACE("interface"),
+ INTERNAL("internal"),
+ INTRINSIC("intrinsic"),
+ IS("is"),
+ NAMESPACE("namespace"),
+ NEW("new"),
+ OVERRIDE("override"),
+ PACKAGE("package"),
+ PRIVATE("private"),
+ PROTECTED("protected"),
+ PUBLIC("public"),
+ RETURN("return"),
+ SET("set"),
+ STATIC("static"),
+ SUPER("super"),
+ SWITCH("switch"),
+ TRY("try"),
+ TYPEOF("typeof"),
+ USE("use"),
+ VAR("var"),
+ VOID("void"),
+ WHILE("while");
+
+ private final String name;
+
+ private KeyWords(final String nameToBeSet) {
+ name = nameToBeSet;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.lang.Enum#toString()
+ */
+ @Override
+ public String toString() {
+ return name;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-api/src/main/java/org/apache/flex/pmd/parser/NodeKind.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/parser/parser-api/src/main/java/org/apache/flex/pmd/parser/NodeKind.java b/FlexPMD/language-module/parser/parser-api/src/main/java/org/apache/flex/pmd/parser/NodeKind.java
new file mode 100644
index 0000000..b5a6eb5
--- /dev/null
+++ b/FlexPMD/language-module/parser/parser-api/src/main/java/org/apache/flex/pmd/parser/NodeKind.java
@@ -0,0 +1,134 @@
+/*
+ * 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 org.apache.flex.pmd.parser;
+
+/**
+ * @author xagnetti
+ */
+public enum NodeKind {
+ ADD("add"),
+ AND("and"),
+ ARGUMENTS("arguments"),
+ ARRAY("array"),
+ ARRAY_ACCESSOR("arr-acc"),
+ AS("as"),
+ AS_DOC("as-doc"),
+ ASSIGN("assign"),
+ B_AND("b-and"),
+ B_NOT("b-not"),
+ B_OR("b-or"),
+ B_XOR("b-xor"),
+ BLOCK("block"),
+ CALL("call"),
+ CASE("case"),
+ CASES("cases"),
+ CATCH("catch"),
+ CLASS("class"),
+ COMPILATION_UNIT("compilation-unit"),
+ COND("cond"),
+ CONDITION("condition"),
+ CONDITIONAL("conditional"),
+ CONST("const"),
+ CONST_LIST("const-list"),
+ CONTENT("content"),
+ DEFAULT("default"),
+ DELETE("delete"),
+ DO("do"),
+ DOT("dot"),
+ E4X_ATTR("e4x-attr"),
+ E4X_FILTER("e4x-filter"),
+ E4X_STAR("e4x-star"),
+ ENCAPSULATED("encapsulated"),
+ EQUALITY("equality"),
+ EXPR_LIST("expr-list"),
+ EXTENDS("extends"),
+ FINALLY("finally"),
+ FOR("for"),
+ FOREACH("foreach"),
+ FORIN("forin"),
+ FUNCTION("function"),
+ GET("get"),
+ IF("if"),
+ IMPLEMENTS("implements"),
+ IMPLEMENTS_LIST("implements-list"),
+ IMPORT("import"),
+ IN("in"),
+ INCLUDE("include"),
+ INIT("init"),
+ INTERFACE("interface"),
+ ITER("iter"),
+ LAMBDA("lambda"),
+ LEFT_CURLY_BRACKET("{"),
+ META("meta"),
+ META_LIST("meta-list"),
+ MINUS("minus"),
+ MOD_LIST("mod-list"),
+ MODIFIER("mod"),
+ MULTI_LINE_COMMENT("multi-line-comment"),
+ MULTIPLICATION("mul"),
+ NAME("name"),
+ NAME_TYPE_INIT("name-type-init"),
+ NEW("new"),
+ NOT("not"),
+ OBJECT("object"),
+ OP("op"),
+ OR("or"),
+ PACKAGE("package"),
+ PARAMETER("parameter"),
+ PARAMETER_LIST("parameter-list"),
+ PLUS("plus"),
+ POST_DEC("post-dec"),
+ POST_INC("post-inc"),
+ PRE_DEC("pre-dec"),
+ PRE_INC("pre-inc"),
+ PRIMARY("primary"),
+ PROP("prop"),
+ RELATION("relation"),
+ REST("rest"),
+ RETURN("return"),
+ SET("set"),
+ SHIFT("shift"),
+ STAR("star"),
+ STMT_EMPTY("stmt-empty"),
+ SWITCH("switch"),
+ SWITCH_BLOCK("switch-block"),
+ TRY("try"),
+ TYPE("type"),
+ TYPEOF("typeof"),
+ USE("use"),
+ VALUE("value"),
+ VAR("var"),
+ VAR_LIST("var-list"),
+ VECTOR("vector"),
+ VOID("void"),
+ WHILE("while");
+
+ private String name;
+
+ private NodeKind(final String nameToBeSet) {
+ name = nameToBeSet;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.lang.Enum#toString()
+ */
+ @Override
+ public String toString() {
+ return name;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-api/src/main/java/org/apache/flex/pmd/parser/Operators.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/parser/parser-api/src/main/java/org/apache/flex/pmd/parser/Operators.java b/FlexPMD/language-module/parser/parser-api/src/main/java/org/apache/flex/pmd/parser/Operators.java
new file mode 100644
index 0000000..4aa4f99
--- /dev/null
+++ b/FlexPMD/language-module/parser/parser-api/src/main/java/org/apache/flex/pmd/parser/Operators.java
@@ -0,0 +1,98 @@
+/*
+ * 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 org.apache.flex.pmd.parser;
+
+/**
+ * @author xagnetti
+ */
+public enum Operators {
+ AND("&&"),
+ AND_AS2("and"),
+ AND_EQUAL("&="),
+ AT("@"),
+ B_AND("&"),
+ B_OR("|"),
+ B_XOR("^"),
+ COLUMN(":"),
+ COMMA(","),
+ DECREMENT("--"),
+ DIVIDED_EQUAL("/="),
+ DOT("."),
+ DOUBLE_COLUMN("::"),
+ DOUBLE_EQUAL("=="),
+ DOUBLE_EQUAL_AS2("eq"),
+ DOUBLE_QUOTE("\""),
+ DOUBLE_SHIFT_LEFT("<<"),
+ DOUBLE_SHIFT_RIGHT(">>"),
+ EQUAL("="),
+ INCREMENT("++"),
+ INFERIOR("<"),
+ INFERIOR_AS2("lt"),
+ INFERIOR_OR_EQUAL("<="),
+ INFERIOR_OR_EQUAL_AS2("le"),
+ LEFT_CURLY_BRACKET("{"),
+ LEFT_PARENTHESIS("("),
+ LEFT_SQUARE_BRACKET("["),
+ LOGICAL_OR("||"),
+ LOGICAL_OR_AS2("or"),
+ MINUS("-"),
+ MINUS_EQUAL("-="),
+ MODULO("%"),
+ MODULO_EQUAL("%="),
+ NON_EQUAL("!="),
+ NON_EQUAL_AS2_1("ne"),
+ NON_EQUAL_AS2_2("<>"),
+ NON_STRICTLY_EQUAL("!=="),
+ OR_EQUAL("|="),
+ PLUS("+"),
+ PLUS_AS2("add"),
+ PLUS_EQUAL("+="),
+ QUESTION_MARK("?"),
+ REST_PARAMETERS("..."),
+ RIGHT_CURLY_BRACKET("}"),
+ RIGHT_PARENTHESIS(")"),
+ RIGHT_SQUARE_BRACKET("]"),
+ SEMI_COLUMN(";"),
+ SIMPLE_QUOTE("'"),
+ SLASH("/"),
+ STRICTLY_EQUAL("==="),
+ SUPERIOR(">"),
+ SUPERIOR_AS2("gt"),
+ SUPERIOR_OR_EQUAL(">="),
+ SUPERIOR_OR_EQUAL_AS2("ge"),
+ TIMES("*"),
+ TIMES_EQUAL("*="),
+ TRIPLE_SHIFT_LEFT("<<<"),
+ TRIPLE_SHIFT_RIGHT(">>>"),
+ VECTOR_START(".<"),
+ XOR_EQUAL("^=");
+
+ private String symbol;
+
+ private Operators(final String symbolToBeSet) {
+ symbol = symbolToBeSet;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.lang.Enum#toString()
+ */
+ @Override
+ public String toString() {
+ return symbol;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-api/src/main/java/org/apache/flex/pmd/parser/ast/FlexNode.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/parser/parser-api/src/main/java/org/apache/flex/pmd/parser/ast/FlexNode.java b/FlexPMD/language-module/parser/parser-api/src/main/java/org/apache/flex/pmd/parser/ast/FlexNode.java
new file mode 100644
index 0000000..ddd0e09
--- /dev/null
+++ b/FlexPMD/language-module/parser/parser-api/src/main/java/org/apache/flex/pmd/parser/ast/FlexNode.java
@@ -0,0 +1,9 @@
+package org.apache.flex.pmd.parser.ast;
+
+import net.sourceforge.pmd.lang.symboltable.ScopedNode;
+
+/**
+ * Created by christoferdutz on 06.03.15.
+ */
+public interface FlexNode extends ScopedNode {
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-api/src/main/java/org/apache/flex/pmd/parser/ast/Token.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/parser/parser-api/src/main/java/org/apache/flex/pmd/parser/ast/Token.java b/FlexPMD/language-module/parser/parser-api/src/main/java/org/apache/flex/pmd/parser/ast/Token.java
new file mode 100644
index 0000000..3274762
--- /dev/null
+++ b/FlexPMD/language-module/parser/parser-api/src/main/java/org/apache/flex/pmd/parser/ast/Token.java
@@ -0,0 +1,72 @@
+package org.apache.flex.pmd.parser.ast;
+
+/**
+ * Created by christoferdutz on 06.03.15.
+ */
+public class Token implements java.io.Serializable {
+ public static Token create(final String textContent,
+ final int tokenLine,
+ final int tokenColumn) {
+ return new Token(textContent, tokenLine, tokenColumn);
+ }
+
+ private final int column;
+ private final boolean isNumeric;
+ private final int line;
+ private final String text;
+
+ /**
+ * @param textContent
+ * @param tokenLine
+ * @param tokenColumn
+ */
+ public Token(final String textContent,
+ final int tokenLine,
+ final int tokenColumn) {
+ this(textContent, tokenLine, tokenColumn, false);
+ }
+
+ /**
+ * @param textContent
+ * @param tokenLine
+ * @param tokenColumn
+ * @param isNumToSet
+ */
+ public Token(final String textContent,
+ final int tokenLine,
+ final int tokenColumn,
+ final boolean isNumToSet) {
+ text = textContent;
+ line = tokenLine + 1;
+ column = tokenColumn + 1;
+ isNumeric = isNumToSet;
+ }
+
+ /**
+ * @return
+ */
+ public int getColumn() {
+ return column;
+ }
+
+ /**
+ * @return
+ */
+ public int getLine() {
+ return line;
+ }
+
+ /**
+ * @return
+ */
+ public String getText() {
+ return text;
+ }
+
+ /**
+ * @return
+ */
+ public boolean isNum() {
+ return isNumeric;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-api/src/main/java/org/apache/flex/pmd/parser/exceptions/NullTokenException.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/parser/parser-api/src/main/java/org/apache/flex/pmd/parser/exceptions/NullTokenException.java b/FlexPMD/language-module/parser/parser-api/src/main/java/org/apache/flex/pmd/parser/exceptions/NullTokenException.java
new file mode 100644
index 0000000..2745ecb
--- /dev/null
+++ b/FlexPMD/language-module/parser/parser-api/src/main/java/org/apache/flex/pmd/parser/exceptions/NullTokenException.java
@@ -0,0 +1,31 @@
+/*
+ * 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 org.apache.flex.pmd.parser.exceptions;
+
+/**
+ * @author xagnetti
+ */
+@SuppressWarnings("serial")
+public class NullTokenException extends TokenException {
+ /**
+ * @param fileName
+ */
+ public NullTokenException(final String fileName) {
+ super("null token in "
+ + fileName + ".");
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-api/src/main/java/org/apache/flex/pmd/parser/exceptions/TokenException.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/parser/parser-api/src/main/java/org/apache/flex/pmd/parser/exceptions/TokenException.java b/FlexPMD/language-module/parser/parser-api/src/main/java/org/apache/flex/pmd/parser/exceptions/TokenException.java
new file mode 100644
index 0000000..2eaeb71
--- /dev/null
+++ b/FlexPMD/language-module/parser/parser-api/src/main/java/org/apache/flex/pmd/parser/exceptions/TokenException.java
@@ -0,0 +1,30 @@
+/*
+ * 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 org.apache.flex.pmd.parser.exceptions;
+
+/**
+ * @author xagnetti
+ */
+@SuppressWarnings("serial")
+public class TokenException extends Exception {
+ /**
+ * @param message
+ */
+ protected TokenException(final String message) {
+ super(message);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-api/src/main/java/org/apache/flex/pmd/parser/exceptions/UnExpectedTokenException.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/parser/parser-api/src/main/java/org/apache/flex/pmd/parser/exceptions/UnExpectedTokenException.java b/FlexPMD/language-module/parser/parser-api/src/main/java/org/apache/flex/pmd/parser/exceptions/UnExpectedTokenException.java
new file mode 100644
index 0000000..df42c29
--- /dev/null
+++ b/FlexPMD/language-module/parser/parser-api/src/main/java/org/apache/flex/pmd/parser/exceptions/UnExpectedTokenException.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 org.apache.flex.pmd.parser.exceptions;
+
+/**
+ * @author xagnetti
+ */
+@SuppressWarnings("serial")
+public class UnExpectedTokenException extends TokenException {
+ public static class Position {
+ private final int column;
+ private final int line;
+
+ public Position(final int lineToBeSet,
+ final int columnToBeSet) {
+ super();
+ line = lineToBeSet;
+ column = columnToBeSet;
+ }
+ }
+
+ /**
+ * @param tokenText
+ * @param tokenPosition
+ * @param fileName
+ * @param expected
+ */
+ public UnExpectedTokenException(final String tokenText,
+ final Position tokenPosition,
+ final String fileName,
+ final String expected) {
+ super("Unexpected token: \""
+ + tokenText + "\" in file (" + fileName + ") at " + tokenPosition.line + ":"
+ + tokenPosition.column + ". Expecting \"" + expected + "\"");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-impl/pom.xml
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/parser/parser-impl/pom.xml b/FlexPMD/language-module/parser/parser-impl/pom.xml
new file mode 100644
index 0000000..6a9275b
--- /dev/null
+++ b/FlexPMD/language-module/parser/parser-impl/pom.xml
@@ -0,0 +1,54 @@
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.flex.pmd.parser</groupId>
+ <artifactId>parser</artifactId>
+ <version>2.0.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>parser-impl</artifactId>
+ <version>2.0.0-SNAPSHOT</version>
+ <packaging>jar</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.flex.pmd.parser</groupId>
+ <artifactId>parser-api</artifactId>
+ <version>2.0.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.flex.pmd</groupId>
+ <artifactId>utils</artifactId>
+ <version>2.0.0-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.testng</groupId>
+ <artifactId>testng</artifactId>
+ <version>6.8.8</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
[22/24] git commit: [flex-utilities]
[refs/heads/feature/pmd-5.2-language-module] - Initial commit of the PMD
language module for Apache Flex
Posted by cd...@apache.org.
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/main/java/org/apache/flex/pmd/parser/impl/AS3Scanner.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/parser/parser-impl/src/main/java/org/apache/flex/pmd/parser/impl/AS3Scanner.java b/FlexPMD/language-module/parser/parser-impl/src/main/java/org/apache/flex/pmd/parser/impl/AS3Scanner.java
new file mode 100644
index 0000000..875ebff
--- /dev/null
+++ b/FlexPMD/language-module/parser/parser-impl/src/main/java/org/apache/flex/pmd/parser/impl/AS3Scanner.java
@@ -0,0 +1,695 @@
+/*
+ * 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 org.apache.flex.pmd.parser.impl;
+
+import org.apache.flex.pmd.parser.ast.Token;
+import org.apache.flex.pmd.utils.StackTraceUtils;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.logging.Logger;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
+
+/**
+ * convert a actionscript to a stream of tokens
+ *
+ * @author rbokel
+ * @author xagnetti
+ */
+public class AS3Scanner {
+
+ private static class XMLVerifier {
+ private static DefaultHandler handler;
+ private static SAXParser saxParser;
+
+ static {
+ final SAXParserFactory factory = SAXParserFactory.newInstance();
+
+ handler = new DefaultHandler();
+ factory.setNamespaceAware(false);
+
+ try {
+ saxParser = factory.newSAXParser();
+ } catch (final ParserConfigurationException e) {
+ LOGGER.warning(StackTraceUtils.print(e));
+ } catch (final SAXException e) {
+ }
+ }
+
+ public static boolean verify(final String text) {
+ try {
+ saxParser.parse(new InputSource(new StringReader(text)),
+ handler);
+ return true;
+ } catch (final SAXException e) {
+ LOGGER.warning(StackTraceUtils.print(e));
+ return false;
+ } catch (final IOException e) {
+ LOGGER.warning(StackTraceUtils.print(e));
+ return false;
+ }
+ }
+ }
+
+ private static final String END = "__END__";
+ private static final Logger LOGGER = Logger.getLogger(AS3Scanner.class.getName());
+
+ protected static boolean isDecimalChar(final char currentCharacter) {
+ return currentCharacter >= '0'
+ && currentCharacter <= '9';
+ }
+
+ private int column;
+ private boolean inVector;
+ private int line;
+ private String[] lines = null;
+
+ /**
+ * @return
+ */
+ public Token moveToNextToken() {
+ return nextToken();
+ }
+
+ /**
+ * @param linesToBeSet
+ */
+ public void setLines(final String[] linesToBeSet) {
+ lines = linesToBeSet;
+ line = 0;
+ column = -1;
+ }
+
+ boolean isHexChar(final char currentCharacter) {
+ final boolean isNum = currentCharacter >= '0'
+ && currentCharacter <= '9';
+ final boolean isLower = currentCharacter >= 'A'
+ && currentCharacter <= 'Z';
+ final boolean isUpper = currentCharacter >= 'a'
+ && currentCharacter <= 'z';
+
+ return isNum
+ || isLower || isUpper;
+ }
+
+ /**
+ * @return
+ */
+ protected Token nextToken() {
+ char currentCharacter;
+
+ if (lines != null
+ && line < lines.length) {
+ currentCharacter = nextNonWhitespaceCharacter();
+ } else {
+ return new Token(END, line, column);
+ }
+
+ if (currentCharacter == '\n') {
+ return new Token("\n", line, column);
+ }
+ if (currentCharacter == '/') {
+ return scanCommentRegExpOrOperator();
+ }
+ if (currentCharacter == '"') {
+ return scanString(currentCharacter);
+ }
+ if (currentCharacter == '\'') {
+ return scanString(currentCharacter);
+ }
+ if (currentCharacter == '<') {
+ return scanXMLOrOperator(currentCharacter);
+ }
+ if (currentCharacter >= '0'
+ && currentCharacter <= '9' || currentCharacter == '.') {
+ return scanNumberOrDots(currentCharacter);
+ }
+ if (currentCharacter == '{'
+ || currentCharacter == '}' || currentCharacter == '(' || currentCharacter == ')'
+ || currentCharacter == '[' || currentCharacter == ']' || currentCharacter == ';'
+ || currentCharacter == ',' || currentCharacter == '?' || currentCharacter == '~') {
+ return scanSingleCharacterToken(currentCharacter);
+ }
+ if (currentCharacter == ':') {
+ return scanCharacterSequence(currentCharacter,
+ new String[]
+ {"::"});
+ }
+ if (currentCharacter == '*') {
+ return scanCharacterSequence(currentCharacter,
+ new String[]
+ {});
+ }
+ if (currentCharacter == '+') {
+ return scanCharacterSequence(currentCharacter,
+ new String[]
+ {"++",
+ "+="});
+ }
+ if (currentCharacter == '-') {
+ return scanCharacterSequence(currentCharacter,
+ new String[]
+ {"--",
+ "-="});
+ }
+ if (currentCharacter == '%') {
+ return scanCharacterSequence(currentCharacter,
+ new String[]
+ {"%="});
+ }
+ if (currentCharacter == '&') {
+ return scanCharacterSequence(currentCharacter,
+ new String[]
+ {"&&",
+ "&="});
+ }
+ if (currentCharacter == '|') {
+ return scanCharacterSequence(currentCharacter,
+ new String[]
+ {"||",
+ "|="});
+ }
+ if (currentCharacter == '^') {
+ return scanCharacterSequence(currentCharacter,
+ new String[]
+ {"^="});
+ }
+ if (currentCharacter == '>') {
+ if (inVector) {
+ inVector = false;
+ } else {
+ return scanCharacterSequence(currentCharacter,
+ new String[]
+ {">>>=",
+ ">>>",
+ ">>=",
+ ">>",
+ ">="});
+ }
+ }
+ if (currentCharacter == '=') {
+ return scanCharacterSequence(currentCharacter,
+ new String[]
+ {"===",
+ "=="});
+ }
+ if (currentCharacter == '!') {
+ return scanCharacterSequence(currentCharacter,
+ new String[]
+ {"!==",
+ "!="});
+ }
+
+ return scanWord(currentCharacter);
+ }
+
+ private int computePossibleMatchesMaxLength(final String[] possibleMatches) {
+ int max = 0;
+
+ for (final String possibleMatch : possibleMatches) {
+ max = Math.max(max,
+ possibleMatch.length());
+ }
+ return max;
+ }
+
+ private char getPreviousCharacter() {
+ int currentIndex = -1;
+ char currentChar;
+ do {
+ currentChar = peekChar(currentIndex--);
+ }
+ while (currentChar == ' ');
+ return currentChar;
+ }
+
+ private boolean isIdentifierCharacter(final char currentCharacter) {
+ return currentCharacter >= 'A'
+ && currentCharacter <= 'Z' || currentCharacter >= 'a' && currentCharacter <= 'z'
+ || currentCharacter >= '0' && currentCharacter <= '9' || currentCharacter == '_'
+ || currentCharacter == '$';
+ }
+
+ private boolean isProcessingInstruction(final String text) {
+ return text.startsWith("<?");
+ }
+
+ private boolean isValidRegExp(final String pattern) {
+ try {
+ Pattern.compile(pattern);
+ } catch (final PatternSyntaxException t) {
+ return false;
+ }
+ return true;
+ }
+
+ private boolean isValidXML(final String text) {
+ return XMLVerifier.verify(text);
+ }
+
+ private char nextChar() {
+ final String currentLine = lines[line];
+
+ column++;
+ if (currentLine.length() <= column) {
+ column = -1;
+ line++;
+ return '\n';
+ }
+
+ char currentChar = currentLine.charAt(column);
+
+ while (currentChar == '\uFEFF') {
+ column++;
+ currentChar = currentLine.charAt(column);
+ }
+ return currentChar;
+ }
+
+ private char nextNonWhitespaceCharacter() {
+ char result;
+ do {
+ result = nextChar();
+ }
+ while (result == ' '
+ || result == '\t');
+ return result;
+ }
+
+ private char peekChar(final int offset) {
+ final String currentLine = lines[line];
+ final int index = column
+ + offset;
+ if (index == -1) {
+ return '\0';
+ }
+ if (index >= currentLine.length()) {
+ return '\n';
+ }
+
+ return currentLine.charAt(index);
+ }
+
+ /**
+ * find the longest matching sequence
+ *
+ * @param currentCharacter
+ * @param possibleMatches
+ * @return
+ */
+ private Token scanCharacterSequence(final char currentCharacter,
+ final String[] possibleMatches) {
+ int peekPos = 1;
+ final StringBuilder buffer = new StringBuilder();
+ final int maxLength = computePossibleMatchesMaxLength(possibleMatches);
+
+ buffer.append(currentCharacter);
+ String found = buffer.toString();
+ while (peekPos < maxLength) {
+ buffer.append(peekChar(peekPos));
+ peekPos++;
+ for (final String possibleMatche : possibleMatches) {
+ if (buffer.toString().equals(possibleMatche)) {
+ found = buffer.toString();
+ }
+ }
+ }
+ final Token result = new Token(found, line, column);
+ skipChars(found.length() - 1);
+ return result;
+ }
+
+ /**
+ * Something started with a slash This might be a comment, a regexp or a
+ * operator
+ *
+ * @return
+ */
+ private Token scanCommentRegExpOrOperator() {
+ final char firstCharacter = peekChar(1);
+
+ if (firstCharacter == '/') {
+ return scanSingleLineComment();
+ }
+ if (firstCharacter == '*') {
+ return scanMultiLineComment();
+ }
+
+ Token result;
+
+ if (getPreviousCharacter() == '='
+ || getPreviousCharacter() == '(' || getPreviousCharacter() == ',') {
+ result = scanRegExp();
+
+ if (result != null) {
+ return result;
+ }
+ }
+
+ if (firstCharacter == '=') {
+ result = new Token("/=", line, column);
+ skipChars(1);
+ return result;
+ }
+ result = new Token("/", line, column);
+ return result;
+ }
+
+ /**
+ * c is either a dot or a number
+ *
+ * @return
+ */
+ private Token scanDecimal(final char currentCharacter) {
+ char currentChar = currentCharacter;
+ final StringBuilder buffer = new StringBuilder();
+ int peekPos = 1;
+
+ while (isDecimalChar(currentChar)) {
+ buffer.append(currentChar);
+ currentChar = peekChar(peekPos++);
+ }
+
+ if (currentChar == '.') {
+ buffer.append(currentChar);
+ currentChar = peekChar(peekPos++);
+
+ while (isDecimalChar(currentChar)) {
+ buffer.append(currentChar);
+ currentChar = peekChar(peekPos++);
+ }
+
+ if (currentChar == 'E') {
+ buffer.append(currentChar);
+ currentChar = peekChar(peekPos++);
+ while (isDecimalChar(currentChar)) {
+ buffer.append(currentChar);
+ currentChar = peekChar(peekPos++);
+ }
+ }
+ }
+ final Token result = new Token(buffer.toString(), line, column, true);
+ skipChars(result.getText().length() - 1);
+ return result;
+ }
+
+ /**
+ * The first dot has been scanned Are the next chars dots as well?
+ *
+ * @return
+ */
+ private Token scanDots() {
+ final char secondCharacter = peekChar(1);
+
+ if (secondCharacter == '.') {
+ final char thirdCharacter = peekChar(2);
+ final String text = thirdCharacter == '.' ? "..."
+ : "..";
+ final Token result = new Token(text, line, column);
+
+ skipChars(text.length() - 1);
+
+ return result;
+ } else if (secondCharacter == '<') {
+ final Token result = new Token(".<", line, column);
+
+ skipChars(1);
+
+ inVector = true;
+ return result;
+ }
+ return null;
+ }
+
+ /**
+ * we have seen the 0x prefix
+ *
+ * @return
+ */
+ private Token scanHex() {
+ final StringBuilder buffer = new StringBuilder();
+
+ buffer.append("0x");
+ int peekPos = 2;
+ for (; ; ) {
+ final char character = peekChar(peekPos++);
+
+ if (!isHexChar(character)) {
+ break;
+ }
+ buffer.append(character);
+ }
+ final Token result = new Token(buffer.toString(), line, column, true);
+ skipChars(result.getText().length() - 1);
+ return result;
+ }
+
+ /**
+ * the current char is the first slash plus we know, that a * is following
+ *
+ * @return
+ */
+ private Token scanMultiLineComment() {
+ final StringBuilder buffer = new StringBuilder();
+ char currentCharacter = ' ';
+ char previousCharacter = ' ';
+
+ buffer.append("/*");
+ skipChar();
+ do {
+ previousCharacter = currentCharacter;
+ currentCharacter = nextChar();
+ buffer.append(currentCharacter);
+ }
+ while (currentCharacter != 0
+ && !(currentCharacter == '/' && previousCharacter == '*'));
+
+ return new Token(buffer.toString(), line, column);
+ }
+
+ /**
+ * Something started with a number or a dot.
+ *
+ * @param characterToBeScanned
+ * @return
+ */
+ private Token scanNumberOrDots(final char characterToBeScanned) {
+ if (characterToBeScanned == '.') {
+ final Token result = scanDots();
+ if (result != null) {
+ return result;
+ }
+
+ final char firstCharacter = peekChar(1);
+ if (!isDecimalChar(firstCharacter)) {
+ return new Token(".", line, column);
+ }
+ }
+ if (characterToBeScanned == '0') {
+ final char firstCharacter = peekChar(1);
+ if (firstCharacter == 'x') {
+ return scanHex();
+ }
+ }
+ return scanDecimal(characterToBeScanned);
+ }
+
+ private Token scanRegExp() {
+ final Token token = scanUntilDelimiter('/');
+ if (token != null
+ && isValidRegExp(token.getText())) {
+ return token;
+ }
+ return null;
+ }
+
+ private Token scanSingleCharacterToken(final char character) {
+ return new Token(String.valueOf(character), line, column);
+ }
+
+ /**
+ * the current char is the first slash plus we know, that another slash is
+ * following
+ *
+ * @return
+ */
+ private Token scanSingleLineComment() {
+ final Token result = new Token(lines[line].substring(column), line, column);
+ skipChars(result.getText().length() - 1);
+ return result;
+ }
+
+ /**
+ * Something started with a quote or double quote consume characters until
+ * the quote/double quote shows up again and is not escaped
+ *
+ * @param startingCharacter
+ * @return
+ */
+ private Token scanString(final char startingCharacter) {
+ return scanUntilDelimiter(startingCharacter);
+ }
+
+ private Token scanUntilDelimiter(final char delimiter) {
+ return scanUntilDelimiter(delimiter,
+ delimiter);
+
+ }
+
+ private Token scanUntilDelimiter(final char start,
+ final char delimiter) {
+ final StringBuilder buffer = new StringBuilder();
+ int peekPos = 1;
+ int numberOfBackslashes = 0;
+
+ buffer.append(start);
+
+ for (; ; ) {
+ final char currentCharacter = peekChar(peekPos++);
+ if (currentCharacter == '\n') {
+ return null;
+ }
+ buffer.append(currentCharacter);
+ if (currentCharacter == delimiter
+ && numberOfBackslashes == 0) {
+ final Token result = Token.create(buffer.toString(),
+ line,
+ column);
+ skipChars(buffer.toString().length() - 1);
+ return result;
+ }
+ numberOfBackslashes = currentCharacter == '\\' ? (numberOfBackslashes + 1) % 2
+ : 0;
+ }
+ }
+
+ private Token scanWord(final char startingCharacter) {
+ char currentChar = startingCharacter;
+ final StringBuilder buffer = new StringBuilder();
+
+ buffer.append(currentChar);
+ int peekPos = 1;
+ for (; ; ) {
+ currentChar = peekChar(peekPos++);
+ if (!isIdentifierCharacter(currentChar)) {
+ break;
+ }
+
+ buffer.append(currentChar);
+ }
+ final Token result = new Token(buffer.toString(), line, column);
+ skipChars(buffer.toString().length() - 1);
+ return result;
+ }
+
+ /**
+ * Try to parse a XML document
+ *
+ * @return
+ */
+ private Token scanXML() {
+ final int currentLine = line;
+ final int currentColumn = column;
+ int level = 0;
+ final StringBuilder buffer = new StringBuilder();
+ char currentCharacter = '<';
+
+ for (; ; ) {
+ Token currentToken = null;
+ do {
+ currentToken = scanUntilDelimiter('<',
+ '>');
+ if (currentToken == null) {
+ line = currentLine;
+ column = currentColumn;
+ return null;
+ }
+ buffer.append(currentToken.getText());
+ if (isProcessingInstruction(currentToken.getText())) {
+ currentCharacter = nextChar();
+ if (currentCharacter == '\n') {
+ buffer.append('\n');
+ skipChar();
+ }
+ currentToken = null;
+ }
+ }
+ while (currentToken == null);
+
+ if (currentToken.getText().startsWith("</")) {
+ level--;
+ } else if (!currentToken.getText().endsWith("/>")
+ && !currentToken.getText().equals("<>")) // NOT operator in AS2
+ {
+ level++;
+ }
+
+ if (level <= 0) {
+ return new Token(buffer.toString(), line, column);
+ }
+
+ for (; ; ) {
+ currentCharacter = nextChar();
+ if (currentCharacter == '<') {
+ break;
+ }
+ buffer.append(currentCharacter);
+ }
+ }
+ }
+
+ /**
+ * Something started with a lower sign <
+ *
+ * @param startingCharacterc
+ * @return
+ */
+ private Token scanXMLOrOperator(final char startingCharacterc) {
+ final Token xmlToken = scanXML();
+
+ if (xmlToken != null
+ && isValidXML(xmlToken.getText())) {
+ return xmlToken;
+ }
+ return scanCharacterSequence(startingCharacterc,
+ new String[]
+ {"<<<=",
+ "<<<",
+ "<<=",
+ "<<",
+ "<="});
+ }
+
+ private void skipChar() {
+ nextChar();
+ }
+
+ private void skipChars(final int count) {
+ int decrementCount = count;
+
+ while (decrementCount-- > 0) {
+ nextChar();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/main/java/org/apache/flex/pmd/parser/impl/NestedNode.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/parser/parser-impl/src/main/java/org/apache/flex/pmd/parser/impl/NestedNode.java b/FlexPMD/language-module/parser/parser-impl/src/main/java/org/apache/flex/pmd/parser/impl/NestedNode.java
new file mode 100644
index 0000000..a98b530
--- /dev/null
+++ b/FlexPMD/language-module/parser/parser-impl/src/main/java/org/apache/flex/pmd/parser/impl/NestedNode.java
@@ -0,0 +1,200 @@
+/*
+ * 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 org.apache.flex.pmd.parser.impl;
+
+import org.apache.flex.pmd.parser.IParserNode;
+import org.apache.flex.pmd.parser.NodeKind;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author xagnetti
+ */
+class NestedNode {
+ private List<IParserNode> children;
+ private NodeKind nodeId;
+
+ /**
+ * @param idToBeSet
+ */
+ protected NestedNode(final NodeKind idToBeSet) {
+ nodeId = idToBeSet;
+ }
+
+ /**
+ * @param idToBeSet
+ * @param childToBeSet
+ */
+ protected NestedNode(final NodeKind idToBeSet,
+ final IParserNode childToBeSet) {
+ this(idToBeSet);
+ addChild(childToBeSet);
+ }
+
+ /**
+ * @return
+ */
+ public final int computeCyclomaticComplexity() {
+ int cyclomaticComplexity = 0;
+
+ if (is(NodeKind.FOREACH)
+ || is(NodeKind.FORIN) || is(NodeKind.CASE) || is(NodeKind.DEFAULT)) {
+ cyclomaticComplexity++;
+ } else if (is(NodeKind.IF)
+ || is(NodeKind.WHILE) || is(NodeKind.FOR)) {
+ cyclomaticComplexity++;
+ cyclomaticComplexity += getChild(0).countNodeFromType(NodeKind.AND);
+ cyclomaticComplexity += getChild(0).countNodeFromType(NodeKind.OR);
+ }
+
+ if (numChildren() > 0) {
+ for (final IParserNode child : getChildren()) {
+ cyclomaticComplexity += child.computeCyclomaticComplexity();
+ }
+ }
+
+ return cyclomaticComplexity;
+ }
+
+ /**
+ * @param type
+ * @return
+ */
+ public final int countNodeFromType(final NodeKind type) {
+ int count = 0;
+
+ if (is(type)) {
+ count++;
+ }
+ if (numChildren() > 0) {
+ for (final IParserNode child : getChildren()) {
+ count += child.countNodeFromType(type);
+ }
+ }
+ return count;
+ }
+
+ /**
+ * @param index
+ * @return
+ */
+ public final IParserNode getChild(final int index) {
+ return getChildren() == null
+ || getChildren().size() <= index ? null
+ : getChildren().get(index);
+ }
+
+ /**
+ * @return
+ */
+ public List<IParserNode> getChildren() {
+ return children;
+ }
+
+ /**
+ * @return
+ */
+ public NodeKind getId() {
+ return nodeId;
+ }
+
+ /**
+ * @return
+ */
+ public IParserNode getLastChild() {
+ final IParserNode lastChild = getChild(numChildren() - 1);
+
+ return lastChild != null
+ && lastChild.numChildren() > 0 ? lastChild.getLastChild()
+ : lastChild;
+ }
+
+ /**
+ * @param expectedType
+ * @return
+ */
+ public final boolean is(final NodeKind expectedType) // NOPMD
+ {
+ return getId().equals(expectedType);
+ }
+
+ /**
+ * @return
+ */
+ public final int numChildren() {
+ return getChildren() == null ? 0
+ : getChildren().size();
+ }
+
+ /**
+ * @param child
+ * @return
+ */
+ final IParserNode addChild(final IParserNode child) {
+ if (child == null) {
+ return child; // skip optional children
+ }
+
+ if (children == null) {
+ children = new ArrayList<IParserNode>();
+ }
+ children.add(child);
+ return child;
+ }
+
+ /**
+ * @param childId
+ * @param childLine
+ * @param childColumn
+ * @param nephew
+ * @return
+ */
+ final IParserNode addChild(final NodeKind childId,
+ final int childLine,
+ final int childColumn,
+ final IParserNode nephew) {
+ return addChild(Node.create(childId,
+ childLine,
+ childColumn,
+ nephew));
+ }
+
+ /**
+ * @param childId
+ * @param childLine
+ * @param childColumn
+ * @param value
+ * @return
+ */
+ final IParserNode addChild(final NodeKind childId,
+ final int childLine,
+ final int childColumn,
+ final String value) {
+ return addChild(Node.create(childId,
+ childLine,
+ childColumn,
+ value));
+ }
+
+ /**
+ * @param idToBeSet
+ */
+ final void setId(final NodeKind idToBeSet) {
+ nodeId = idToBeSet;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/main/java/org/apache/flex/pmd/parser/impl/Node.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/parser/parser-impl/src/main/java/org/apache/flex/pmd/parser/impl/Node.java b/FlexPMD/language-module/parser/parser-impl/src/main/java/org/apache/flex/pmd/parser/impl/Node.java
new file mode 100644
index 0000000..a88b912
--- /dev/null
+++ b/FlexPMD/language-module/parser/parser-impl/src/main/java/org/apache/flex/pmd/parser/impl/Node.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 org.apache.flex.pmd.parser.impl;
+
+import org.apache.flex.pmd.parser.IParserNode;
+import org.apache.flex.pmd.parser.NodeKind;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * A single node of the ast
+ *
+ * @author rbokel
+ */
+final class Node extends NestedNode implements IParserNode {
+ protected static Node create(final NodeKind idToBeSet,
+ final int lineToBeSet,
+ final int columnToBeSet) {
+ return new Node(idToBeSet, lineToBeSet, columnToBeSet);
+ }
+
+ protected static Node create(final NodeKind idToBeSet,
+ final int lineToBeSet,
+ final int columnToBeSet,
+ final IParserNode childToBeSet) {
+ return new Node(idToBeSet, lineToBeSet, columnToBeSet, childToBeSet);
+ }
+
+ protected static Node create(final NodeKind idToBeSet,
+ final int lineToBeSet,
+ final int columnToBeSet,
+ final String valueToBeSet) {
+ return new Node(idToBeSet, lineToBeSet, columnToBeSet, valueToBeSet);
+ }
+
+ private static boolean isNameInArray(final String[] strings,
+ final String string) {
+ for (final String currentName : strings) {
+ if (currentName.equals(string)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private final int column;
+ private final int line;
+ private final String stringValue;
+
+ private Node(final NodeKind idToBeSet,
+ final int lineToBeSet,
+ final int columnToBeSet) {
+ super(idToBeSet);
+
+ line = lineToBeSet;
+ column = columnToBeSet;
+ stringValue = null;
+ }
+
+ private Node(final NodeKind idToBeSet,
+ final int lineToBeSet,
+ final int columnToBeSet,
+ final IParserNode childToBeSet) {
+ super(idToBeSet, childToBeSet);
+
+ line = lineToBeSet;
+ column = columnToBeSet;
+ stringValue = null;
+ }
+
+ private Node(final NodeKind idToBeSet,
+ final int lineToBeSet,
+ final int columnToBeSet,
+ final String valueToBeSet) {
+ super(idToBeSet);
+
+ line = lineToBeSet;
+ column = columnToBeSet;
+ stringValue = valueToBeSet;
+ }
+
+ public List<IParserNode> findPrimaryStatementsFromNameInChildren(final String[] names) {
+ final List<IParserNode> foundNode = new ArrayList<IParserNode>();
+
+ if (getStringValue() != null
+ && isNameInArray(names,
+ getStringValue())) {
+ foundNode.add(this);
+ } else if (numChildren() != 0) {
+ for (final IParserNode child : getChildren()) {
+ foundNode.addAll(child.findPrimaryStatementsFromNameInChildren(names));
+ }
+ }
+ return foundNode;
+ }
+
+ public int getColumn() {
+ return column;
+ }
+
+ public int getLine() {
+ return line;
+ }
+
+ public String getStringValue() {
+ return stringValue;
+ }
+
+ @Override
+ public String toString() {
+ final StringBuilder buffer = new StringBuilder();
+
+ if (getStringValue() == null) {
+ buffer.append(getId());
+ } else {
+ buffer.append(getStringValue());
+ }
+
+ buffer.append(' ');
+
+ if (getChildren() != null) {
+ for (final IParserNode child : getChildren()) {
+ buffer.append(child.toString());
+ buffer.append(' ');
+ }
+ }
+ return buffer.toString();
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/AbstractAs3ParserTestBase.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/AbstractAs3ParserTestBase.java b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/AbstractAs3ParserTestBase.java
new file mode 100644
index 0000000..7bf16c3
--- /dev/null
+++ b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/AbstractAs3ParserTestBase.java
@@ -0,0 +1,74 @@
+/*
+ * 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 org.apache.flex.pmd.parser.impl;
+
+import org.apache.flex.pmd.parser.IParserNode;
+import org.testng.annotations.BeforeMethod;
+
+public abstract class AbstractAs3ParserTestBase {
+
+ protected final class ASTToXMLConverter {
+ public String convert(final IParserNode ast) {
+ final StringBuilder result = new StringBuilder();
+ visitNodes(ast, result, 0);
+ return result.toString();
+ }
+ }
+
+ private static String escapeEntities(final String stringToEscape) {
+ final StringBuilder buffer = new StringBuilder();
+
+ for (int i = 0; i < stringToEscape.length(); i++) {
+ final char currentCharacter = stringToEscape.charAt(i);
+
+ if (currentCharacter == '<') {
+ buffer.append("<");
+ } else if (currentCharacter == '>') {
+ buffer.append(">");
+ } else {
+ buffer.append(currentCharacter);
+ }
+ }
+ return buffer.toString();
+ }
+
+ private static void visitNodes(final IParserNode ast,
+ final StringBuilder result,
+ final int level) {
+ result.append("<").append(ast.getId()).append(" line=\"").append(ast.getLine()).append("\">");
+
+ final int numChildren = ast.numChildren();
+ if (numChildren > 0) {
+ for (int i = 0; i < numChildren; i++) {
+ visitNodes(ast.getChild(i), result, level + 1);
+ }
+ } else if (ast.getStringValue() != null) {
+ result.append(escapeEntities(ast.getStringValue()));
+ }
+ result.append("</").append(ast.getId()).append(">");
+ }
+
+ protected AS3Parser asp;
+ protected AS3Scanner scn;
+
+ @BeforeMethod(alwaysRun = true)
+ public void setUp() {
+ asp = new AS3Parser(null);
+ scn = asp.getScn();
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/AbstractStatementTestBase.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/AbstractStatementTestBase.java b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/AbstractStatementTestBase.java
new file mode 100644
index 0000000..4bf1dca
--- /dev/null
+++ b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/AbstractStatementTestBase.java
@@ -0,0 +1,34 @@
+/*
+ * 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 org.apache.flex.pmd.parser.impl;
+
+import static org.testng.Assert.*;
+
+import org.apache.flex.pmd.parser.exceptions.TokenException;
+
+public abstract class AbstractStatementTestBase extends AbstractAs3ParserTestBase {
+
+ protected void assertStatement(final String message,
+ final String input,
+ final String expected) throws TokenException {
+ scn.setLines(new String[] {input, "__END__"});
+ asp.nextToken();
+ final String result = new ASTToXMLConverter().convert(asp.parseStatement());
+ assertEquals(expected, result, message);
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/NestedNodeTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/NestedNodeTest.java b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/NestedNodeTest.java
new file mode 100644
index 0000000..4d50d65
--- /dev/null
+++ b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/NestedNodeTest.java
@@ -0,0 +1,77 @@
+/*
+ * 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 org.apache.flex.pmd.parser.impl;
+
+import static org.testng.Assert.*;
+
+import org.apache.flex.pmd.parser.NodeKind;
+import org.apache.flex.pmd.parser.exceptions.TokenException;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+public class NestedNodeTest extends AbstractAs3ParserTestBase {
+
+ private NestedNode function;
+
+ @Override
+ @BeforeMethod
+ public void setUp() {
+ super.setUp();
+
+ final String code = "public function foo() : void {"
+ + "while(i>0){" + "while(true){" + "switch(a){" + "case 1:break;default:return;" + "}" + "}"
+ + "}" + "}";
+ final Node classNode = parseClass(code);
+
+ function = (Node) classNode.getChild(0);
+ }
+
+ @Test
+ public void testComputeCyclomaticComplexity() {
+ assertEquals(5, function.computeCyclomaticComplexity());
+ }
+
+ @Test
+ public void testCountNodeFromType() {
+ assertEquals(2, function.countNodeFromType(NodeKind.WHILE));
+ }
+
+ @Test
+ public void testGetLastChild() {
+ assertEquals(NodeKind.RETURN, function.getLastChild().getId());
+
+ assertNull(function.getChild(Integer.MAX_VALUE));
+ }
+
+ @Test
+ public void testIs() {
+ assertFalse(function.is(null));
+ }
+
+ private Node parseClass(final String input) {
+ scn.setLines(new String[]
+ {"{", input, "}", "__END__"});
+ try {
+ asp.nextToken();
+ asp.nextToken(); // skip {
+ return asp.parseClassContent();
+ } catch (final TokenException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/NodeTest.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/NodeTest.java b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/NodeTest.java
new file mode 100644
index 0000000..ca59b93
--- /dev/null
+++ b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/NodeTest.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 org.apache.flex.pmd.parser.impl;
+
+import static org.testng.Assert.*;
+
+import org.apache.flex.pmd.parser.exceptions.TokenException;
+import org.testng.annotations.Test;
+
+public class NodeTest extends AbstractAs3ParserTestBase {
+
+ @Test
+ public void testFindPrimaryStatementsFromNameInChildren() throws TokenException {
+ final Node ast = parseFunction("function set a( value : int ) : void { trace(\"lala\")}");
+
+ assertEquals(2,
+ ast.findPrimaryStatementsFromNameInChildren(new String[]
+ {"trace",
+ "\"lala\""}).size());
+ }
+
+ @Test
+ public void testToString() throws TokenException {
+ final Node ast = parseFunction("function set a( value : int ) : void { trace(\"lala\")}");
+
+ assertEquals("content set mod-list a parameter-list parameter name-type-init "
+ + "value int void block call trace arguments \"lala\" ",
+ ast.toString());
+ }
+
+ private Node parseFunction(final String input) throws TokenException {
+ scn.setLines(new String[]
+ {"{",
+ input,
+ "}",
+ "__END__"});
+ asp.nextToken(); // first call
+ asp.nextToken(); // skip {
+ return asp.parseClassContent();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestAS3Parser.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestAS3Parser.java b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestAS3Parser.java
new file mode 100644
index 0000000..2860721
--- /dev/null
+++ b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestAS3Parser.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 org.apache.flex.pmd.parser.impl;
+
+import static org.testng.Assert.*;
+
+import org.apache.flex.pmd.parser.IParserNode;
+import org.apache.flex.pmd.parser.exceptions.TokenException;
+import org.apache.flex.pmd.utils.FileUtils;
+import org.testng.annotations.Test;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URISyntaxException;
+
+public class TestAS3Parser extends AbstractAs3ParserTestBase {
+
+ @Test
+ public void testBuildAst_AS2() throws IOException,
+ URISyntaxException,
+ TokenException {
+ asp.buildAst(getClass().getResource("/examples/toAS2/src/fw/data/request/ResultListener.as")
+ .toURI()
+ .getPath());
+
+ // Remark: file was missing.
+ //asp.buildAst( getClass().getResource( "/examples/toAS2/src/epg/StateExit_AS2.as" ).toURI().getPath() );
+ }
+
+ @Test
+ public void testBuildAst() throws IOException, URISyntaxException, TokenException {
+ asp.buildAst(getClass().getResource("/examples/unformatted/IContext.as").toURI().getPath());
+ asp.buildAst(getClass().getResource("/examples/FlexPMD115.as").toURI().getPath());
+ asp.buildAst(getClass().getResource("/examples/JPEGEncoder.as").toURI().getPath());
+ asp.buildAst(getClass().getResource("/examples/JPEGEncoder2.as").toURI().getPath());
+ asp.buildAst(getClass().getResource("/examples/FisheyeBase.as").toURI().getPath());
+ asp.buildAst(getClass().getResource("/examples/FlexPMD98.as").toURI().getPath());
+ asp.buildAst(getClass().getResource("/examples/FlexPMD195.as").toURI().getPath());
+ final String titlePath = getClass().getResource("/examples/unformatted/Title.as").toURI().getPath();
+
+ asp.buildAst(titlePath);
+ asp.buildAst(titlePath,
+ FileUtils.readLines(new File(titlePath)));
+ }
+
+ @Test
+ public void testBuildAst2() throws IOException,
+ TokenException,
+ URISyntaxException {
+ final IParserNode flexPmd62 = asp.buildAst(getClass().getResource("/examples/FlexPMD62.as")
+ .toURI()
+ .getPath());
+
+ assertEquals("com.test.testy.ui.components",
+ flexPmd62.getChild(0).getChild(0).getStringValue());
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestAS3Scanner.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestAS3Scanner.java b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestAS3Scanner.java
new file mode 100644
index 0000000..5e930f3
--- /dev/null
+++ b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestAS3Scanner.java
@@ -0,0 +1,322 @@
+/*
+ * 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 org.apache.flex.pmd.parser.impl;
+
+import static org.testng.Assert.*;
+
+import org.apache.flex.pmd.parser.ast.Token;
+import org.testng.annotations.Test;
+
+public class TestAS3Scanner extends AbstractAs3ParserTestBase {
+
+ @Test
+ public void testAssignments() {
+ final String[] lines = new String[]
+ {"=",
+ "+=",
+ "-=",
+ "%=",
+ "^=",
+ "&=",
+ "|=",
+ "/="};
+ scn.setLines(lines);
+
+ for (int i = 0; i < lines.length; i++) {
+ assertText(Integer.toString(i),
+ lines[i]);
+ assertText("\n");
+ }
+ }
+
+ @Test
+ public void testBooleanOperators() {
+ final String[] lines = new String[]
+ {"&&",
+ "&=",
+ "||",
+ "|="};
+ scn.setLines(lines);
+
+ for (int i = 0; i < lines.length; i++) {
+ assertText(Integer.toString(i),
+ lines[i]);
+ assertText("\n");
+ }
+ }
+
+ @Test
+ public void testComparisonOperators() {
+ final String[] lines = new String[]
+ {">",
+ ">>>=",
+ ">>>",
+ ">>=",
+ ">>",
+ ">=",
+ "===",
+ "==",
+ "!==",
+ "!="};
+ scn.setLines(lines);
+
+ for (int i = 0; i < lines.length; i++) {
+ assertText(Integer.toString(i),
+ lines[i]);
+ assertText("\n");
+ }
+ }
+
+ @Test
+ public void testIdentifiers() {
+ final String[] lines = new String[]
+ {"a",
+ "a.b.*",
+ "a.b::c",
+ "a.E"};
+ scn.setLines(lines);
+
+ assertText("1",
+ lines[0]);
+ assertText("\n");
+
+ assertText("2",
+ "a");
+ assertText("2",
+ ".");
+ assertText("2",
+ "b");
+ assertText("2",
+ ".");
+ assertText("2",
+ "*");
+ assertText("\n");
+
+ assertText("3",
+ "a");
+ assertText("3",
+ ".");
+ assertText("3",
+ "b");
+ assertText("3",
+ "::");
+ assertText("3",
+ "c");
+ assertText("\n");
+
+ assertText("4",
+ "a");
+ assertText("4",
+ ".");
+ assertText("4",
+ "E");
+ }
+
+ @Test
+ public void testIsDecimalChar() {
+ final String decimalString = "0123456789";
+ for (int i = 0; i < decimalString.length(); i++) {
+ assertTrue(AS3Scanner.isDecimalChar(decimalString.charAt(i)));
+ }
+ assertFalse(AS3Scanner.isDecimalChar((char) 0));
+
+ }
+
+ @Test
+ public void testIsHex() {
+ assertTrue(scn.isHexChar('0'));
+ assertTrue(scn.isHexChar('9'));
+ assertTrue(scn.isHexChar('A'));
+ assertTrue(scn.isHexChar('a'));
+ assertTrue(scn.isHexChar('F'));
+ assertTrue(scn.isHexChar('f'));
+ assertFalse(scn.isHexChar(';'));
+ assertFalse(scn.isHexChar(']'));
+ assertFalse(scn.isHexChar(' '));
+ }
+
+ @Test
+ public void testMultiLineComment() {
+ final String[] lines = new String[]
+ {"/* this is a multi line comment, not really */",
+ "/** now for real",
+ "/* now for real",
+ "*/"};
+ scn.setLines(lines);
+
+ assertText(lines[0]);
+ assertText("\n");
+ assertText("/** now for real\n/* now for real\n*/");
+ }
+
+ @Test
+ public void testMultilineXML() {
+ final String[] lines = new String[]
+ {"<?xml version=\"1.0\"?>",
+ "<a>",
+ "<b>test</b>",
+ "</a>"};
+ scn.setLines(lines);
+ assertText(join(lines,
+ "\n"));
+ }
+
+ @Test
+ public void testMultipleWords() {
+ final String[] lines = new String[]
+ {"word1 word2 word3",
+ "word4",
+ "word5 word6"};
+ scn.setLines(lines);
+
+ assertText("word1");
+ assertText("word2");
+ assertText("word3");
+ assertText("\n");
+ assertText("word4");
+ assertText("\n");
+ assertText("word5");
+ assertText("word6");
+ }
+
+ @Test
+ public void testNumbers() {
+ final String[] lines = new String[]
+ {"0",
+ "1.2",
+ "1.2E5",
+ "0xffgg"};
+ scn.setLines(lines);
+
+ assertText(lines[0]);
+ assertText("\n");
+ assertText(lines[1]);
+ assertText("\n");
+ assertText(lines[2]);
+ assertText("\n");
+ assertText(lines[3]);
+ }
+
+ @Test
+ public void testPlusSymbols() {
+ final String[] lines = new String[]
+ {"++",
+ "+=",
+ "+",
+ "--",
+ "-=",
+ "-"};
+ scn.setLines(lines);
+
+ for (int i = 0; i < lines.length; i++) {
+ assertText(Integer.toString(i),
+ lines[i]);
+ assertText("\n");
+ }
+ }
+
+ @Test
+ public void testSingleCharacterSymbols() {
+ final String[] lines = "{}()[]:;,?~".split("");
+ scn.setLines(lines);
+
+ // the first entry is empty, so we skip it
+ for (int i = 1; i < lines.length; i++) {
+ assertText("\n");
+ assertText(Integer.toString(i),
+ lines[i]);
+ }
+ }
+
+ @Test
+ public void testSingleLineComment() {
+ final String[] lines = new String[]
+ {"//this is a single line comment",
+ "word //another single line comment"};
+ scn.setLines(lines);
+
+ assertText(lines[0]);
+ assertText("\n");
+ assertText("word");
+ assertText("//another single line comment");
+ }
+
+ @Test
+ public void testSingleWord() {
+ final String[] lines = new String[]
+ {"word"};
+ scn.setLines(lines);
+
+ assertText(lines[0]);
+ }
+
+ @Test
+ public void testStrings() {
+ final String[] lines = new String[]
+ {"\"string\"",
+ "\'string\'",
+ "\"string\\\"\""};
+ scn.setLines(lines);
+
+ assertText("1",
+ lines[0]);
+ assertText("\n");
+ assertText("2",
+ lines[1]);
+ assertText("\n");
+ assertText("3",
+ lines[2]);
+ }
+
+ @Test
+ public void testXML() {
+ final String[] lines = new String[]
+ {"<root/>",
+ "<root>test</root>",
+ "<?xml version=\"1.0\"?><root>test</root>"};
+ scn.setLines(lines);
+ for (int i = 0; i < lines.length; i++) {
+ assertText(Integer.toString(i),
+ lines[i]);
+ assertText("\n");
+ }
+ }
+
+ private void assertText(final String text) {
+ assertText("",
+ text);
+ }
+
+ private void assertText(final String message,
+ final String text) {
+ Token token = scn.nextToken();
+ assertEquals(text,
+ token.getText(), message);
+ }
+
+ private String join(final String[] lines,
+ final String delimiter) {
+ final StringBuilder result = new StringBuilder();
+ for (int i = 0; i < lines.length; i++) {
+ if (i > 0) {
+ result.append(delimiter);
+ }
+ result.append(lines[i]);
+ }
+ return result.toString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestAS3ScannerWithFiles.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestAS3ScannerWithFiles.java b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestAS3ScannerWithFiles.java
new file mode 100644
index 0000000..2cd057f
--- /dev/null
+++ b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestAS3ScannerWithFiles.java
@@ -0,0 +1,88 @@
+/*
+ * 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 org.apache.flex.pmd.parser.impl;
+
+import static org.testng.Assert.*;
+
+import org.apache.flex.pmd.parser.ast.Token;
+import org.apache.flex.pmd.utils.FileUtils;
+import org.testng.annotations.Test;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URISyntaxException;
+
+public class TestAS3ScannerWithFiles extends AbstractAs3ParserTestBase {
+
+ @Test(enabled = false)
+ // Simple.as has the completely wrong structure ... have to fix this first.
+ public void testSimple() throws IOException,
+ URISyntaxException {
+ final String[] expected = new String[]
+ {"package",
+ "simple",
+ "{",
+ "public",
+ "class",
+ "Simple",
+ "{",
+ "public",
+ "function",
+ "Simple",
+ "(",
+ ")",
+ "{",
+ "trace",
+ "(",
+ "\"Simple\"",
+ ")",
+ ";",
+ "}",
+ "}"};
+/* assertFile( expected,
+ "Simple.as" );
+*/
+ }
+
+ private void assertFile(final String[] expected,
+ final String fileName) throws IOException,
+ URISyntaxException {
+ final String[] lines = FileUtils.readLines(new File(getClass().getResource("/examples/unformatted/")
+ .toURI()
+ .getPath()
+ + fileName));
+ assertLines(expected,
+ lines);
+ }
+
+ private void assertLines(final String[] expected,
+ final String[] lines) {
+ scn.setLines(lines);
+ for (int i = 0; i < expected.length; i++) {
+ assertText(Integer.toString(i),
+ expected[i]);
+ }
+ }
+
+ private void assertText(final String message,
+ final String text) {
+ Token token = scn.nextToken();
+ assertEquals(message,
+ text,
+ token.getText());
+ }
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestClass.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestClass.java b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestClass.java
new file mode 100644
index 0000000..600d6d2
--- /dev/null
+++ b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestClass.java
@@ -0,0 +1,129 @@
+/*
+ * 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 org.apache.flex.pmd.parser.impl;
+
+import static org.testng.Assert.*;
+
+import org.apache.flex.pmd.parser.exceptions.TokenException;
+
+public class TestClass extends AbstractAs3ParserTestBase {
+
+ public void testExtends() throws TokenException {
+ assertPackageContent("1",
+ "public class A extends B { } ",
+ "<content line=\"2\">"
+ + "<class line=\"2\">" + "<name line=\"2\">A</name><mod-list line=\"2\">"
+ + "<mod line=\"2\">public</mod></mod-list><extends line=\"2\""
+ + ">B</extends><content line=\"2\"></content>" + "</class></content>");
+
+ assertPackageContent("1",
+ "public class A extends com.adobe::B { } ",
+ "<content line=\"2\"><class line=\"2\"><name line=\"2\""
+ + ">A</name><mod-list line=\"2\"><mod line=\"2\""
+ + ">public</mod></mod-list><extends line=\"2\""
+ + ">com.adobe::B</extends><content line=\"2\"></content>"
+ + "</class></content>");
+ }
+
+ public void testFinalClass() throws TokenException {
+ assertPackageContent("",
+ "public final class Title{ }",
+ "<content line=\"2\">"
+ + "<class line=\"2\">" + "<name line=\"2\">Title</name>"
+ + "<mod-list line=\"2\">" + "<mod line=\"2\">public</mod>"
+ + "<mod line=\"2\">final</mod></mod-list>" + "<content line=\"2\""
+ + "></content>" + "</class>" + "</content>");
+ }
+
+ public void testFullFeatured() throws TokenException {
+ // assertPackageContent( "",
+ // "public class A { public static const RULE_REMOVED : String = \"ruleRemoved\";}",
+ // "" );
+
+ assertPackageContent("1",
+ "public class A extends B implements C,D { } ",
+ "<content line=\"2\"><class line=\"2\">"
+ + "<name line=\"2\">A</name><mod-list line=\"2\">"
+ + "<mod line=\"2\">public</mod></mod-list><extends line=\"2\""
+ + ">B</extends><implements-list line=\"2\">"
+ + "<implements line=\"2\">C</implements><implements line=\"2\""
+ + ">D</implements></implements-list><content line=\"2\">"
+ + "</content></class></content>");
+ }
+
+ public void testImplementsList() throws TokenException {
+ assertPackageContent("1",
+ "public class A implements B,C { } ",
+ "<content line=\"2\"><class line=\"2\">"
+ + "<name line=\"2\">A</name><mod-list line=\"2\""
+ + "><mod line=\"2\">public</mod></mod-list>"
+ + "<implements-list line=\"2\"><implements line=\"2\""
+ + ">B</implements><implements line=\"2\">"
+ + "C</implements></implements-list><content line=\"2\">"
+ + "</content></class></content>");
+ }
+
+ public void testImplementsSingle() throws TokenException {
+ assertPackageContent("1",
+ "public class A implements B { } ",
+ "<content line=\"2\"><class line=\"2\">"
+ + "<name line=\"2\">A</name><mod-list line=\"2\""
+ + "><mod line=\"2\">public</mod></mod-list>"
+ + "<implements-list line=\"2\"><implements line=\"2\""
+ + ">B</implements></implements-list><content line=\"2\""
+ + "></content></class></content>");
+ }
+
+ public void testImportInsideClass() throws TokenException {
+ assertPackageContent("",
+ "public final class Title{ import lala.lala; }",
+ "<content line=\"2\">"
+ + "<class line=\"2\"><name line=\"2\">Title</name>"
+ + "<mod-list line=\"2\"><mod line=\"2\">public</mod>"
+ + "<mod line=\"2\">final</mod></mod-list>"
+ + "<content line=\"2\"><import line=\"2\""
+ + ">lala.lala</import></content></class></content>");
+
+ }
+
+ public void testInclude() throws TokenException {
+ assertPackageContent("1",
+ "public class A extends B { include \"ITextFieldInterface.asz\" } ",
+ "<content line=\"2\"><class line=\"2\">"
+ + "<name line=\"2\">A</name><mod-list line=\"2\">"
+ + "<mod line=\"2\">public</mod></mod-list>"
+ + "<extends line=\"2\">B</extends>"
+ + "<content line=\"2\"></content></class></content>");
+ }
+
+ private void assertPackageContent(final String message,
+ final String input,
+ final String expected) throws TokenException {
+ scn.setLines(new String[]
+ {"{",
+ input,
+ "}",
+ "__END__"});
+ asp.nextToken(); // first call
+ asp.nextToken(); // skip {
+ final String result = new ASTToXMLConverter().convert(asp.parsePackageContent());
+ assertEquals(message,
+ expected,
+ result);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/flex-utilities/blob/ff722d6f/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestClassContent.java
----------------------------------------------------------------------
diff --git a/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestClassContent.java b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestClassContent.java
new file mode 100644
index 0000000..124c339
--- /dev/null
+++ b/FlexPMD/language-module/parser/parser-impl/src/test/java/org/apache/flex/pmd/parser/impl/TestClassContent.java
@@ -0,0 +1,285 @@
+/*
+ * 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 org.apache.flex.pmd.parser.impl;
+
+import static org.testng.Assert.*;
+
+import org.apache.flex.pmd.parser.exceptions.TokenException;
+import org.testng.annotations.Test;
+
+public class TestClassContent extends AbstractAs3ParserTestBase {
+
+ @Test
+ public void testCommentInMethod() throws TokenException {
+ assertClassContent("",
+ "public function log():void{/* comment */}",
+ "<function line=\"2\"><mod-list line=\"2\"><mod "
+ + "line=\"2\">public</mod></mod-list><name line=\"2\">log</name>"
+ + "<parameter-list line=\"2\"></parameter-list><type line=\"2\">"
+ + "void</type><block line=\"2\"><multi-line-comment line=\"2\">"
+ + "/* comment */</multi-line-comment></block></function>");
+
+ assertClassContent("",
+ new String[]
+ {"{",
+ "public function log():void{// comment ",
+ "}",
+ "}",
+ "__END__"},
+ "<function line=\"2\"><mod-list line=\"2\"><mod line=\"2\""
+ + ">public</mod></mod-list><name line=\"2\">log</name>"
+ + "<parameter-list line=\"2\"></parameter-list><type line=\"2\""
+ + ">void</type><block line=\"2\"></block></function>");
+ }
+
+ @Test
+ public void testConstDeclarations() throws TokenException {
+ assertClassContent("1",
+ "const a",
+ "<const-list line=\"2\"><mod-list line=\"2\">"
+ + "</mod-list><name-type-init line=\"2\"><name line=\"2\">a"
+ + "</name><type line=\"3\"></type></name-type-init></const-list>");
+
+ assertClassContent("2",
+ "public const a",
+ "<const-list line=\"2\"><mod-list line=\"2\">"
+ + "<mod line=\"2\">public</mod></mod-list><name-type-init line=\"2\""
+ + "><name line=\"2\">a</name><type line=\"3\">"
+ + "</type></name-type-init></const-list>");
+
+ assertClassContent("3",
+ "public static const a : int = 0",
+ "<const-list line=\"2\"><mod-list line=\"2\">"
+ + "<mod line=\"2\">public</mod><mod line=\"2\">"
+ + "static</mod></mod-list><name-type-init line=\"2\"><name "
+ + "line=\"2\">a</name><type line=\"2\">int</type>"
+ + "<init line=\"2\"><primary line=\"2\">0</primary>"
+ + "</init></name-type-init></const-list>");
+
+ assertClassContent("4",
+ "[Bindable] const a",
+ "<const-list line=\"2\"><meta-list line=\"2\">"
+ + "<meta line=\"2\">Bindable</meta></meta-list><mod-list line=\"2\""
+ + "></mod-list><name-type-init line=\"2\">"
+ + "<name line=\"2\">a</name><type line=\"3\">"
+ + "</type></name-type-init></const-list>");
+ }
+
+ @Test
+ public void testFlexPMD211() throws TokenException {
+ assertClassContent("",
+ "private function foo(sf:int):void{"
+ + "var a:Vector.<String> = new Vector.<String>()}",
+ "<function line=\"2\"><mod-list line=\"2\"><mod line=\"2\">private</mod>"
+ + "</mod-list><name line=\"2\">foo</name><parameter-list line=\"2\">"
+ + "<parameter line=\"2\"><name-type-init line=\"2\"><name line=\"2\">sf</name>"
+ + "<type line=\"2\">int</type></name-type-init></parameter></parameter-list>"
+ + "<type line=\"2\">void</type><block line=\"2\"><var-list line=\"2\">"
+ + "<name-type-init line=\"2\"><name line=\"2\">a</name><vector line=\"2\">"
+ + "<type line=\"2\">String</type></vector><init line=\"2\"><new line=\"2\">"
+ + "<primary line=\"2\">Vector</primary><vector line=\"2\"><vector line=\"2\">"
+ + "<type line=\"2\">String</type></vector></vector><arguments line=\"2\">"
+ + "</arguments></new></init></name-type-init></var-list></block></function>");
+ assertClassContent("",
+ "private function foo(sf:int):void{"
+ + "var a:Vector.<String> = new Vector.<String>();}",
+ "<function line=\"2\"><mod-list line=\"2\"><mod line=\"2\">private</mod></mod-list>"
+ + "<name line=\"2\">foo</name><parameter-list line=\"2\"><parameter line=\"2\">"
+ + "<name-type-init line=\"2\"><name line=\"2\">sf</name><type line=\"2\">int</type>"
+ + "</name-type-init></parameter></parameter-list><type line=\"2\">void</type>"
+ + "<block line=\"2\"><var-list line=\"2\"><name-type-init line=\"2\">"
+ + "<name line=\"2\">a</name><vector line=\"2\"><type line=\"2\">String</type>"
+ + "</vector><init line=\"2\"><new line=\"2\"><primary line=\"2\">Vector</primary>"
+ + "<vector line=\"2\"><vector line=\"2\"><type line=\"2\">String</type></vector>"
+ + "</vector><arguments line=\"2\"></arguments></new></init></name-type-init>"
+ + "</var-list></block></function>");
+ }
+
+ @Test
+ public void testImports() throws TokenException {
+ assertClassContent("1",
+ "import a.b.c;",
+ "<import line=\"2\">a.b.c</import>");
+ assertClassContent("2",
+ "import a.b.c import x.y.z",
+ "<import line=\"2\">a.b.c</import>"
+ + "<import line=\"2\">x.y.z</import>");
+ }
+
+ @Test
+ public void testMethods() throws TokenException {
+ assertClassContent("1",
+ "function a(){}",
+ "<function line=\"2\"><mod-list line=\"2\">"
+ + "</mod-list><name line=\"2\">a</name><parameter-list line=\"2\""
+ + "></parameter-list><type line=\"2\"></type><block "
+ + "line=\"2\"></block></function>");
+
+ assertClassContent("2",
+ "function set a( value : int ) : void {}",
+ "<set line=\"2\"><mod-list line=\"2\">"
+ + "</mod-list><name line=\"2\">a</name>"
+ + "<parameter-list line=\"2\"><parameter line=\"2\">"
+ + "<name-type-init line=\"2\"><name line=\"2\">value"
+ + "</name><type line=\"2\">int</type></name-type-init></parameter>"
+ + "</parameter-list><type line=\"2\">void</type><block line=\"2\""
+ + "></block></set>");
+
+ assertClassContent("3",
+ "function get a() : int {}",
+ "<get line=\"2\"><mod-list line=\"2\">"
+ + "</mod-list><name line=\"2\">a</name><parameter-list line=\"2\""
+ + "></parameter-list><type line=\"2\">int"
+ + "</type><block line=\"2\"></block></get>");
+
+ assertClassContent("function with default parameter",
+ "public function newLine ( height:*='' ):void{}",
+ "<function line=\"2\"><mod-list line=\"2\"><mod line=\"2\""
+ + ">public</mod></mod-list><name line=\"2\">newLine"
+ + "</name><parameter-list line=\"2\"><parameter line=\"2\""
+ + "><name-type-init line=\"2\"><name line=\"2\""
+ + ">height</name><type line=\"2\">*</type>"
+ + "<init line=\"2\"><primary line=\"2\">''"
+ + "</primary></init></name-type-init></parameter></parameter-list>"
+ + "<type line=\"2\">void</type><block line=\"2\">" + "</block></function>");
+ }
+
+ @Test
+ public void testMethodsWithAsDoc() throws TokenException {
+ scn.setLines(new String[]
+ {"{",
+ "/** AsDoc */public function a(){}",
+ "}",
+ "__END__"});
+ asp.nextToken(); // first call
+ asp.nextToken(); // skip {
+
+ assertEquals("<content line=\"2\"><function line=\"2\">"
+ + "<as-doc line=\"2\">/** AsDoc */</as-doc><mod-list "
+ + "line=\"2\"><mod line=\"2\">public</mod>"
+ + "</mod-list><name line=\"2\">a</name><parameter-list "
+ + "line=\"2\"></parameter-list><type line=\"2\">"
+ + "</type><block line=\"2\"></block></function></content>",
+ new ASTToXMLConverter().convert(asp.parseClassContent()));
+ }
+
+ @Test
+ public void testMethodsWithMultiLineComments() throws TokenException {
+ scn.setLines(new String[]
+ {"{",
+ "/* Commented */public function a(){}",
+ "}",
+ "__END__"});
+ asp.nextToken(); // first call
+ asp.nextToken(); // skip {
+
+ assertEquals("<content line=\"2\"><multi-line-comment line=\"2\">"
+ + "/* Commented */</multi-line-comment><function line=\"2\">"
+ + "<mod-list line=\"2\"><mod line=\"2\">public"
+ + "</mod></mod-list><name line=\"2\">a</name><parameter-list "
+ + "line=\"2\"></parameter-list><type line=\"2\">"
+ + "</type><block line=\"2\"></block></function></content>",
+ new ASTToXMLConverter().convert(asp.parseClassContent()));
+ }
+
+ @Test
+ public void testMethodWithMetadataComment() throws TokenException {
+ scn.setLines(new String[]
+ {"{",
+ "/* Comment */ [Bindable] public function a () : void { }",
+ "}",
+ "__END__"});
+ asp.nextToken(); // first call
+ asp.nextToken(); // skip {
+
+ assertEquals("<content line=\"2\"><multi-line-comment line=\"2\">"
+ + "/* Comment */</multi-line-comment><function line=\"2\">"
+ + "<meta-list line=\"2\"><meta line=\"2\">Bindable"
+ + "</meta></meta-list><mod-list line=\"2\"><mod line=\"2\""
+ + ">public</mod></mod-list><name line=\"2\">a</name>"
+ + "<parameter-list line=\"2\"></parameter-list><type line=\"2\""
+ + ">void</type><block line=\"2\"></block></function>" + "</content>",
+ new ASTToXMLConverter().convert(asp.parseClassContent()));
+ }
+
+ @Test
+ public void testRestParameter() throws TokenException {
+ assertClassContent("",
+ "public function log(message:String, ... rest):void{}",
+ "<function line=\"2\"><mod-list line=\"2\">"
+ + "<mod line=\"2\">public</mod></mod-list><name line=\"2\">"
+ + "log</name><parameter-list line=\"2\">"
+ + "<parameter line=\"2\"><name-type-init line=\"2\">"
+ + "<name line=\"2\">message</name><type line=\"2\">String"
+ + "</type></name-type-init></parameter><parameter line=\"2\">"
+ + "<rest line=\"2\">rest</rest></parameter></parameter-list>"
+ + "<type line=\"2\">void</type><block line=\"2\">" + "</block></function>");
+ }
+
+ @Test
+ public void testVarDeclarations() throws TokenException {
+ assertClassContent("1",
+ "var a",
+ "<var-list line=\"2\"><mod-list line=\"2\">"
+ + "</mod-list><name-type-init line=\"2\"><name line=\"2\">a"
+ + "</name><type line=\"3\"></type></name-type-init></var-list>");
+
+ assertClassContent("2",
+ "public var a;",
+ "<var-list line=\"2\"><mod-list line=\"2\">"
+ + "<mod line=\"2\">public</mod></mod-list><name-type-init line=\"2\""
+ + "><name line=\"2\">a</name><type line=\"2\""
+ + "></type></name-type-init></var-list>");
+
+ assertClassContent("3",
+ "public static var a : int = 0",
+ "<var-list line=\"2\"><mod-list line=\"2\">"
+ + "<mod line=\"2\">public</mod><mod line=\"2\">"
+ + "static</mod></mod-list><name-type-init line=\"2\">"
+ + "<name line=\"2\">a</name><type line=\"2\">int</type>"
+ + "<init line=\"2\"><primary line=\"2\">0</primary>"
+ + "</init></name-type-init></var-list>");
+
+ assertClassContent("4",
+ "[Bindable] var a",
+ "<var-list line=\"2\"><meta-list line=\"2\">"
+ + "<meta line=\"2\">Bindable</meta></meta-list>"
+ + "<mod-list line=\"2\"></mod-list>" + "<name-type-init line=\"2\">"
+ + "<name line=\"2\">a</name><type line=\"3\">"
+ + "</type></name-type-init></var-list>");
+ }
+
+ private void assertClassContent(final String message,
+ final String input,
+ final String expected) throws TokenException {
+ scn.setLines(new String[] {"{", input, "}", "__END__"});
+ asp.nextToken(); // first call
+ asp.nextToken(); // skip {
+ final String result = new ASTToXMLConverter().convert(asp.parseClassContent());
+ assertEquals("<content line=\"2\">" + expected + "</content>", result, message);
+ }
+
+ private void assertClassContent(final String message,
+ final String[] input,
+ final String expected) throws TokenException {
+ scn.setLines(input);
+ asp.nextToken(); // first call
+ asp.nextToken(); // skip {
+ final String result = new ASTToXMLConverter().convert(asp.parseClassContent());
+ assertEquals("<content line=\"2\">" + expected + "</content>", result, message);
+ }
+}