flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cd...@apache.org
Subject [19/24] git commit: [flex-utilities] [refs/heads/feature/pmd-5.2-language-module] - Initial commit of the PMD language module for Apache Flex
Date Sat, 07 Mar 2015 12:07:12 GMT
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() {
+    }
+}


Mime
View raw message