java

位置:IT落伍者 >> java >> 浏览文章

让你知道:java 文件的缩进排版


发布日期:2021年01月07日
 
让你知道:java 文件的缩进排版

//以下是我做的java 文件的缩进排版算法有缺点但能用

//不管怎么说排java文件时比UltralEdit的排版强

import javaioFile;

import javaioPrintStream;

import javautilArrayList;

import langStr;

import langout;

import utilLoad;

class DentJavaCode

{

public static boolean dent(File file File file)

{

String as[] = new String[];

if(file == null || !fileexists())

{

return false;

} else

{

as = py(file as);

ArrayList arraylist = new ArrayList();

dent(as arraylist );

as = (String[])arraylisttoArray(as);

outb(slen= + aslength);

py(as file);

return true;

}

}

public static int dent(ArrayList arraylist ArrayList arraylist int i)

{

if(arraylist == null && arraylistsize() == )

{

Systemoutprintln(dent frm listbut list isnull);

return i;

}

if(arraylist == null)

{

Systemoutprintln(dent to listbut list is null);

return i;

} else

{

String as[] = new String[];

as = (String[])arraylisttoArray(as);

return dent(as arraylist i);

}

}

public static String[] dent(String as[] String as[] int i)

{

ArrayList arraylist = new ArrayList();

dent(as arraylist i);

if(as == null)

as = new String[];

return (String[])arraylisttoArray(as);

}

public static int dent(String as[] ArrayList arraylist int i)

{

int j = aslength;

boolean flag = false;

if(as == null || aslength == )

{

Systemoutprintln(dent from s[]but s[] is null);

return i;

}

if(arraylist == null)

{

Systemoutprintln(dent to listbut list is null);

return i;

}

for(int l = ; l < as.length; l++)

{

if(as[l] == null)

continue;

as[l] = as[l].trim();

int k = as[l].length();

if(k == 0)

continue;

int i1 = Str9.indexOf_outQuotes(special, as[l]);

if(i1 < 0)

{

if(flag)

arraylist.add(space(2) + as[l]);

else

arraylist.add(space(i) + as[l]);

continue;

}

String s = as[l].substring(i1);

if(s.indexOf("{") == 0)

s = "{";

else

if(s.indexOf("}") == 0)

s = "}";

else

if(s.indexOf("//") == 0)

s = "//";

else

if(s.indexOf("*/") == 0)

s = "*/";

else

if(s.indexOf("/*") == 0)

s = "/*";

if(s.equals("//"))

{

if(i1 > 0)

{

arraylist.add(space(i) + as[l].substring(0, i1));

arraylist.add(space(i) + as[l].substring(i1));

} else

{

arraylist.add(space(i) + as[l]);

}

continue;

}

if(s.equals("*/"))

{

flag = false;

if(i1 > )

arraylistadd(space() + as[l]substring( i));

arraylistadd(*/);

i += ;

if(k > i)

{

as[l] = as[l]substring(i);

l;

}

continue;

}

if(sequals(/*))

{

flag = true;

if(i > )

{

arraylistadd(space(i) + as[l]substring( i));

as[l] = as[l]substring(i);

}

if((i = StrindexOf_outQuotes(*/ as[l] i + )) != )

{

flag = false;

i += ;

arraylistadd(as[l]substring( i));

if(as[l]length() > i)

{

as[l] = as[l]substring(i);

l;

}

continue;

}

if(as[l]length() <= )

continue;

arraylistadd(/*);

as[l] = as[l]substring();

if(as[l]length() > )

arraylistadd(space() + as[l]);

continue;

}

if(sequals({))

{

i++;

if(as[l]indexOf(//) == i)

{

arraylistadd(space(i) + as[l]);

i += increment;

continue;

}

arraylistadd(space(i) + as[l]substring( i));

i += increment;

if(k > i)

{

as[l] = as[l]substring(i);

l;

}

continue;

}

if(sequals(}))

{

arraylistadd(space(i) + as[l]substring( i));

i = increment;

i++;

if(k > i && as[l]charAt(i) == ;)

{

arraylistadd(space(i) + };);

i++;

if(k > i)

{

as[l] = as[l]substring(i);

l;

}

continue;

}

if(as[l]indexOf(}//) == )

{

Systemoutprintln(s[i]= + as[l] + indent= + i);

arraylistadd(space(i) + as[l]);

continue;

}

arraylistadd(space(i) + });

if(k > i)

{

as[l] = as[l]substring(i);

l;

}

} else

{

arraylistadd(space(i) + as[l]);

}

}

return i;

}

static String space(int i)

{

return Strrepeat( i);

}

public DentJavaCode(File file)

{

String as[] = null;

as = py(file as);

ArrayList arraylist = new ArrayList();

dent(as arraylist );

String s = filegetName();

int i = ;

boolean flag = false;

File file;

file = file = new File(s + dent);

i = ;

do

{

if(i >= )

break;

file = new File(s + dent + i);

if(!fileexists())

break;

i++;

} while(true);

if(fileexists())

filedelete();

if(filerenameTo(file))

{

String as[] = (String[])arraylisttoArray(as);

py(as file);

Systemoutprintln(ok);

} else

{

Systemoutprintln(rename:false);

}

}

public static void main(String args[])

{

String args[] = new String[];

File file = new File(args[]);

args = py(file args);

ArrayList arraylist = new ArrayList();

dent(args arraylist );

File file = new File(args[] + dent);

int i = ;

do

{

if(i >= )

break;

file = new File(args[] + dent + i);

if(!fileexists())

break;

i++;

} while(true);

if(fileexists())

filedelete();

String args[] = (String[])arraylisttoArray(args);

if(filerenameTo(file))

{

py(args file);

Systemoutprintln(ok);

} else

{

Systemoutprintln(rename:false);

}

}

static int increment = ;

public static String special[] = {

{ } // /* */

};

}

               

上一篇:Java的破解和反破解

下一篇:使用 Java 存储过程将更加简便