2222import org .eclipse .core .runtime .QualifiedName ;
2323import org .eclipse .dltk .compiler .problem .DefaultProblemIdentifier ;
2424import org .eclipse .dltk .compiler .problem .IProblem ;
25- import org .eclipse .dltk .compiler .problem .ProblemSeverities ;
2625import org .eclipse .dltk .compiler .problem .ProblemSeverity ;
2726import org .phpsrc .eclipse .pti .core .launching .OperatingSystem ;
2827import org .phpsrc .eclipse .pti .core .launching .PHPToolLauncher ;
4544
4645public class PHPCodeSniffer extends AbstractPHPTool {
4746
48- public final static QualifiedName QUALIFIED_NAME = new QualifiedName (PHPCodeSnifferPlugin . PLUGIN_ID ,
49- "phpCodeSnifferTool" );
47+ public final static QualifiedName QUALIFIED_NAME = new QualifiedName (
48+ PHPCodeSnifferPlugin . PLUGIN_ID , "phpCodeSnifferTool" );
5049 private static PHPCodeSniffer instance ;
5150
5251 protected PHPCodeSniffer () {
@@ -60,12 +59,14 @@ public static PHPCodeSniffer getInstance() {
6059 }
6160
6261 public IProblem [] parse (IFile file ) throws CoreException , IOException {
63- PHPCodeSnifferPreferences prefs = PHPCodeSnifferPreferencesFactory .factory (file );
62+ PHPCodeSnifferPreferences prefs = PHPCodeSnifferPreferencesFactory
63+ .factory (file );
6464 if (canParse (prefs .getIgnorePattern (), prefs .getFileExtensions (), file )) {
6565
6666 ArrayList <IProblem > list = new ArrayList <IProblem >(10 );
6767 for (Standard standard : prefs .getStandards ()) {
68- IProblem [] problems = parseOutput (new PHPSourceFile (file ), launchFile (file , prefs , standard ), prefs );
68+ IProblem [] problems = parseOutput (new PHPSourceFile (file ),
69+ launchFile (file , prefs , standard ), prefs );
6970 for (IProblem problem : problems )
7071 if (!list .contains (problem ))
7172 list .add (problem );
@@ -77,7 +78,8 @@ public IProblem[] parse(IFile file) throws CoreException, IOException {
7778 }
7879 }
7980
80- protected boolean canParse (String ignorePattern , String [] fileExtensions , IFile file ) {
81+ protected boolean canParse (String ignorePattern , String [] fileExtensions ,
82+ IFile file ) {
8183 boolean can = true ;
8284
8385 if (fileExtensions != null && fileExtensions .length > 0 ) {
@@ -100,7 +102,8 @@ protected boolean canParse(String ignorePattern, String[] fileExtensions, IFile
100102 for (String pattern : patterns ) {
101103 pattern = pattern .trim ();
102104 if (pattern .length () > 0 ) {
103- pattern = pattern .replace ("\\ " , "/" ).replace ("." , "\\ ." ).replace ("*" , ".*" ).replace ("?" , ".?" );
105+ pattern = pattern .replace ("\\ " , "/" ).replace ("." , "\\ ." )
106+ .replace ("*" , ".*" ).replace ("?" , ".?" );
104107 Pattern p = Pattern .compile (pattern );
105108 if (p .matcher (filePath ).matches ()) {
106109 can = false ;
@@ -113,11 +116,13 @@ protected boolean canParse(String ignorePattern, String[] fileExtensions, IFile
113116 return can ;
114117 }
115118
116- protected String launchFile (IFile file , PHPCodeSnifferPreferences prefs , Standard standard ) {
119+ protected String launchFile (IFile file , PHPCodeSnifferPreferences prefs ,
120+ Standard standard ) {
117121
118122 String output = null ;
119123 try {
120- PHPToolLauncher launcher = getPHPToolLauncher (file .getProject (), prefs , standard );
124+ PHPToolLauncher launcher = getPHPToolLauncher (file .getProject (),
125+ prefs , standard );
121126 output = launcher .launch (file );
122127 } catch (Exception e ) {
123128 Logger .logException (e );
@@ -129,7 +134,8 @@ protected String launchFile(IFile file, PHPCodeSnifferPreferences prefs, Standar
129134 return output ;
130135 }
131136
132- protected IProblem [] parseOutput (ISourceFile file , String output , PHPCodeSnifferPreferences prefs ) {
137+ protected IProblem [] parseOutput (ISourceFile file , String output ,
138+ PHPCodeSnifferPreferences prefs ) {
133139 ArrayList <IProblem > problems = new ArrayList <IProblem >();
134140
135141 try {
@@ -147,10 +153,14 @@ protected IProblem[] parseOutput(ISourceFile file, String output, PHPCodeSniffer
147153 parser .parse (new InputSource (new StringReader (output )));
148154
149155 Document doc = parser .getDocument ();
150- problems .addAll (createProblemMarker (file , doc .getElementsByTagName ("error" ),
151- ProblemSeverity .ERROR , tabWidth , prefs .getIgnoreSniffs ()));
152- problems .addAll (createProblemMarker (file , doc .getElementsByTagName ("warning" ),
153- ProblemSeverity .WARNING , tabWidth , prefs .getIgnoreSniffs ()));
156+ problems .addAll (createProblemMarker (file ,
157+ doc .getElementsByTagName ("error" ),
158+ ProblemSeverity .ERROR , tabWidth ,
159+ prefs .getIgnoreSniffs ()));
160+ problems .addAll (createProblemMarker (file ,
161+ doc .getElementsByTagName ("warning" ),
162+ ProblemSeverity .WARNING , tabWidth ,
163+ prefs .getIgnoreSniffs ()));
154164 }
155165 }
156166 } catch (Exception e ) {
@@ -160,7 +170,8 @@ protected IProblem[] parseOutput(ISourceFile file, String output, PHPCodeSniffer
160170 return problems .toArray (new IProblem [0 ]);
161171 }
162172
163- protected ArrayList <IProblem > createProblemMarker (ISourceFile file , NodeList list , ProblemSeverity type , int tabWidth ,
173+ protected ArrayList <IProblem > createProblemMarker (ISourceFile file ,
174+ NodeList list , ProblemSeverity type , int tabWidth ,
164175 String [] ignoreSniffs ) {
165176 if (tabWidth <= 0 )
166177 tabWidth = 2 ;
@@ -186,37 +197,45 @@ protected ArrayList<IProblem> createProblemMarker(ISourceFile file, NodeList lis
186197 continue ;
187198 }
188199
189- int lineNr = Integer .parseInt (attr .getNamedItem ("line" ).getTextContent ());
190- int column = Integer .parseInt (attr .getNamedItem ("column" ).getTextContent ());
200+ int lineNr = Integer .parseInt (attr .getNamedItem ("line" )
201+ .getTextContent ());
202+ int column = Integer .parseInt (attr .getNamedItem ("column" )
203+ .getTextContent ());
191204 int lineStart = file .lineStart (lineNr );
192205
193206 // calculate real column with tabs
194207 if (column > 1 )
195208 lineStart += (column - 1 - (file .lineStartTabCount (lineNr ) * (tabWidth - 1 )));
196209
197- System .out .println (IProblem .Syntax );
198- System .out .println (DefaultProblemIdentifier .decode (IProblem .Syntax ));
199- problems .add (new CodeSnifferProblem (file .getFile ().getFullPath ().toOSString (), item .getTextContent (),
200- DefaultProblemIdentifier .decode (IProblem .Syntax ), new String [0 ], type , lineStart , file .lineEnd (lineNr ), lineNr , column , source ));
210+ problems .add (new CodeSnifferProblem (file .getFile ().getFullPath ()
211+ .toOSString (), item .getTextContent (),
212+ DefaultProblemIdentifier .decode (IProblem .Syntax ),
213+ new String [0 ], type , lineStart , file .lineEnd (lineNr ),
214+ lineNr , column , source ));
201215 }
202216
203217 return problems ;
204218 }
205219
206- protected PHPToolLauncher getPHPToolLauncher (IProject project , PHPCodeSnifferPreferences prefs , Standard standard ) {
220+ protected PHPToolLauncher getPHPToolLauncher (IProject project ,
221+ PHPCodeSnifferPreferences prefs , Standard standard ) {
207222 PHPToolLauncher launcher ;
208223 try {
209- launcher = (PHPToolLauncher ) project .getSessionProperty (QUALIFIED_NAME );
224+ launcher = (PHPToolLauncher ) project
225+ .getSessionProperty (QUALIFIED_NAME );
210226 if (launcher != null ) {
211- launcher .setCommandLineArgs (getCommandLineArgs (standard , prefs .getTabWidth ()));
227+ launcher .setCommandLineArgs (getCommandLineArgs (standard ,
228+ prefs .getTabWidth ()));
212229 return launcher ;
213230 }
214231 } catch (CoreException e ) {
215232 Logger .logException (e );
216233 }
217234
218- launcher = new PHPToolLauncher (QUALIFIED_NAME , getPHPExecutable (prefs .getPhpExecutable ()), getScriptFile (),
219- getCommandLineArgs (standard , prefs .getTabWidth ()), getPHPINIEntries (prefs , project , standard ));
235+ launcher = new PHPToolLauncher (QUALIFIED_NAME ,
236+ getPHPExecutable (prefs .getPhpExecutable ()), getScriptFile (),
237+ getCommandLineArgs (standard , prefs .getTabWidth ()),
238+ getPHPINIEntries (prefs , project , standard ));
220239
221240 launcher .setPrintOuput (prefs .isPrintOutput ());
222241
@@ -229,21 +248,25 @@ protected PHPToolLauncher getPHPToolLauncher(IProject project, PHPCodeSnifferPre
229248 return launcher ;
230249 }
231250
232- private INIFileEntry [] getPHPINIEntries (PHPCodeSnifferPreferences prefs , IProject project , Standard standard ) {
251+ private INIFileEntry [] getPHPINIEntries (PHPCodeSnifferPreferences prefs ,
252+ IProject project , Standard standard ) {
233253
234- IPath [] includePaths = PHPCodeSnifferPlugin .getDefault ().getPluginIncludePaths (project );
254+ IPath [] includePaths = PHPCodeSnifferPlugin .getDefault ()
255+ .getPluginIncludePaths (project );
235256
236257 if (standard .custom ) {
237258 IPath [] tmpIncludePaths = new IPath [includePaths .length + 2 ];
238- System .arraycopy (includePaths , 0 , tmpIncludePaths , 2 , includePaths .length );
259+ System .arraycopy (includePaths , 0 , tmpIncludePaths , 2 ,
260+ includePaths .length );
239261 tmpIncludePaths [0 ] = new Path (standard .path );
240262 tmpIncludePaths [1 ] = new Path (standard .path ).removeLastSegments (1 );
241263 includePaths = tmpIncludePaths ;
242264 }
243265
244266 INIFileEntry [] entries ;
245267 if (includePaths .length > 0 ) {
246- entries = new INIFileEntry [] { INIFileUtil .createIncludePathEntry (includePaths ) };
268+ entries = new INIFileEntry [] { INIFileUtil
269+ .createIncludePathEntry (includePaths ) };
247270 } else {
248271 entries = new INIFileEntry [0 ];
249272 }
@@ -252,13 +275,15 @@ private INIFileEntry[] getPHPINIEntries(PHPCodeSnifferPreferences prefs, IProjec
252275 }
253276
254277 public static IPath getScriptFile () {
255- return PHPCodeSnifferPlugin .getDefault ().resolvePluginResource ("/php/tools/phpcs.php" );
278+ return PHPCodeSnifferPlugin .getDefault ().resolvePluginResource (
279+ "/php/tools/phpcs.php" );
256280 }
257281
258282 private String getCommandLineArgs (Standard standard , int tabWidth ) {
259283
260284 String args = "--report=xml --standard="
261- + (standard .custom ? OperatingSystem .escapeShellFileArg (standard .path ) : OperatingSystem
285+ + (standard .custom ? OperatingSystem
286+ .escapeShellFileArg (standard .path ) : OperatingSystem
262287 .escapeShellArg (standard .name ));
263288
264289 if (tabWidth > 0 )
0 commit comments