import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;


public class FindNoSpace {
    
    
public static void main(String[] args) throws Exception {
        FindNoSpace instance 
= new FindNoSpace();
        
{
            String[] folderNames 
= {"E:\\MyJava\\src"};
            ArrayList fileList 
= instance.getFileListByFileNames(folderNames, false);
            fileList 
= instance.getFileListByParentFolder(fileList, new String[] {".java"}true);
            instance.findNoSpaceFunction(fileList);
        }

//        {
//            String[] folderNames = {"E:\\MyJava\\src\\F01.java"};
//            ArrayList fileList = instance.getFileListByFileNames(folderNames, true);
//            instance.findNoSpaceFunction(fileList);
//        }
    }

    
    
public ArrayList getFileListByParentFolder(ArrayList fileList, String[] endWith, boolean hasChildFoldersChildrens) {
        
boolean hasFolder = true;
        
while (hasFolder) {
            hasFolder 
= false;
            
if (fileList.size() <= 0{
                
break;
            }

            ArrayList newFileList 
= new ArrayList();
            
for (int i = 0; i < fileList.size(); i++{
                File fTem 
= (File)fileList.get(i);
                
if (fTem.isDirectory()) {
                    hasFolder 
= true;
                    File[] filelisttem 
= fTem.listFiles();
                    
for (int j = 0; j < filelisttem.length; j++{
                        
if (filelisttem[j].isDirectory() || isEndWith(filelisttem[j].getName(), endWith))
                            newFileList.add(filelisttem[j]);
                    }

                }
 else if (fTem.isFile()) {
                    
if (isEndWith(fTem.getName(), endWith))
                        newFileList.add(fTem);
                }

            }

            fileList 
= newFileList;
            
if (!hasChildFoldersChildrens) {
                newFileList 
= new ArrayList();
                
for (int i = 0; i <= fileList.size(); i++{
                    File f 
= (File)fileList.get(i);
                    
if (f.isFile()) {
                        newFileList.add(f);
                    }

                }

                fileList 
= newFileList;
                
break;
            }

        }

        
return fileList;
    }

    
    
public ArrayList getFileListByFileNames(String[] fileNames, boolean onlyGetFile) {
        ArrayList fileList 
= new ArrayList();
        
for (int i = 0; i < fileNames.length; i++{
            File f 
= new File(fileNames[i]);
            
if (onlyGetFile && f.isFile()) {
                fileList.add(f);
            }
 else {
                fileList.add(f);
            }

        }

        
return fileList;
    }

    
    
private boolean isEndWith(String str, String[] endWith) {
        
if (endWith.length <= 0{
            
return true;
        }

        str 
= str.toLowerCase();
        
for (int i = 0; i < endWith.length; i++{
            
if (str.endsWith(endWith[i])) {
                
return true;
            }

        }

        
return false;
    }

    
    
public void findNoSpaceFunction(ArrayList fileList) throws Exception{
        
        String line 
= "";
        String[] macher 
= {".*\\w(\\{|==|!=|<=|>=|&&|\\*=|/=|\\+=|-=|%=|^=|\\+|\\-|\\*|/|%|=|<|>)(\\s|\\t).*",
                            
".*(\\s|\\t)(==|!=|<=|>=|&&|\\*=|/=|\\+=|-=|%=|^=|\\+|\\-|\\*|/|%|=|<|>)[\\w|-].*",
                            
".*\\w(==|!=|<=|>=|&&|\\*=|/=|\\+=|-=|%=|^=|\\+|\\-|\\*|/|%|=|<|>)\\w.*",
                            
".*(\\s|\\t)if\\(.*"}
;
        
int onefilelinecount = 0;
        
boolean isPrintfile;
        
for (int i = 0; i < fileList.size(); i++{
            onefilelinecount 
= 0;
            isPrintfile 
= true;
            File f 
= (File)fileList.get(i);
            BufferedReader bfreader 
= new BufferedReader(new FileReader(f));
            
while (bfreader.ready()) {
                onefilelinecount
++;
                line 
= bfreader.readLine();
                
if (line.trim().length() <= 0{
                    
continue;
                }

                
char lt = line.trim().charAt(0);
                
if ("{}0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".indexOf(lt) < 0{
                    
continue;
                }

                
if (line.matches(".*\\s-\\d.*")) {
                    
continue;
                }

                line 
= line.split("//")[0];
                line 
= line.split("/*")[0];
                
if (line.indexOf('"'>= 0{
                    String[] liness 
= line.split("\"");
                    for (int lc = 0; lc < liness.length; lc++{
                        
if (lc % 2 == 0{
                            line 
+= liness[lc];
                        }

                    }

                }

                String teststr 
= line.replaceAll("\\+\\+""\\-\\-");
                teststr 
= teststr.replaceAll("\\-\\-""OO");
                
for (int j = 0; j < macher.length; j++{
                    
if (teststr.matches(macher[j]) || teststr.indexOf("if(">= 0{
                        
if (isPrintfile) {
                            isPrintfile 
= false;
                            System.out.println(f.getAbsolutePath());
                        }

                        System.out.println(onefilelinecount 
+ "\t" + line);
                        
break;
                    }

                }

            }

        }

        System.out.println(
"Find Over");
    }

}