|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
你希望java的IDE整合。这个是没有必要的,重要的是你理解java有多深以及怎么组织你的代码,即使没有IDE,代码照样能够编译运行的。高亮显现|天生htmlimportjava.util.*;
importjava.io.*;
publicclassjava2html
{
privatestaticbooleancomment=false;
privatestaticbooleanlineComment=false;
privatestaticbooleanSTART=true;
privatestaticbooleanEND=false;
privatestaticbooleanbackslash=false;
privatestaticbooleanstringlit=false;
privatestaticbooleanstringlit2=false;
privatestaticinttabWidth=0;
privatestaticStringtab="";
privatestaticCollectionvarList=newArrayList();
privatestaticStringBufferout=newStringBuffer();
privatestaticCollectionprimitives=newArrayList();
static
{
String[]primString=
{"int","Integer","byte","Byte","boolean","Boolean","short","Short","long","Long","char","Character","float","Float","double","Double","String","void","StringBuffer","Collection"};
for(inti=0;i<primString.length;i++)
primitives.add(primString[i]);
}
privatestaticCollectionoperators=newArrayList();
static
{
String[]operString=
{"=",">","<","!","~","?",":","==","<=",">=","!=","&&","||","++","--","+","-","*","/","&","|","^","%",">>","<<",">>>","+=","-=","*=","/=","&=","|=","^=","%=","<<=",">>=","<<<"};
for(inti=0;i<operString.length;i++)
operators.add(operString[i]);
}
privatestaticCollectionstring=newArrayList();
static
{
String[]stringString=
{"""};
for(inti=0;i<stringString.length;i++)
string.add(stringString[i]);
}
privatestaticCollectionflow=newArrayList();
static
{
String[]flowString=
{"true","false","null","import"};
for(inti=0;i<flowString.length;i++)
flow.add(flowString[i]);
}
privatestaticCollectionresWords=newArrayList();
static
{
String[]reswString=
{"private","static","new","public","final","class","this","synchronized","native","package","if","then","else","finally","switch","do","while","case","default","return","break","continue","throw","throws","catch","try","for","protected"};
for(inti=0;i<reswString.length;i++)
resWords.add(reswString[i]);
}
privatestaticvoidjava2html(StringfileName)
{}
publicstaticvoidtabIncrease(booleanup)
{
//prComment(START);out.append("tabs");prComment(END);
if(up)
{
tabWidth++;
}else
{
tabWidth--;
}
tab="";
for(inti=tabWidth;i>0;i--)
{
tab=tab+"";
}
}
publicstaticvoidprTitle(Stringstr)
{
out.append("<TITLE>"+str+"</TITLE>");
out.append("
");
}
publicstaticvoidprPrimitive(Stringstr)
{
if(comment||lineComment)
{
prJComment(str);
}elseif(stringlit)
{
prStringLit(str);
}else
{
out.append("<b><FONTcolor=red>"+str+"</FONT></b>");
out.append("
");
}
}
publicstaticvoidprVar(Stringstr)
{
if(comment||lineComment)
{
prJComment(str);
}elseif(stringlit)
{
prStringLit(str);
}else
{
out.append("<FONTcolor=red>"+str+"</FONT>");
out.append("
");
}
}
publicstaticvoidprFlow(Stringstr)
{
if(comment||lineComment)
{
prJComment(str);
}elseif(stringlit)
{
prStringLit(str);
}else
{
out.append("<b><FONTcolor=black>"+str+"</FONT></b>");
out.append("
");
}
}
publicstaticvoidprResWord(Stringstr)
{
if(comment||lineComment)
{
prJComment(str);
}elseif(stringlit)
{
prStringLit(str);
}else
{
out.append("<b><FONTcolor=black>"+str+"</FONT></b>");
out.append("
");
}
}
publicstaticvoidprNormal(Stringstr)
{
if(comment||lineComment)
{
prJComment(str);
}elseif(stringlit)
{
prStringLit(str);
}else
{
out.append(str);
out.append("
");
}
}
publicstaticvoidprJComment(Stringstr)
{
out.append("<FONTcolor=#888888>"+str+"</FONT>");
out.append("
");
}
publicstaticvoidprOperator(Stringstr)
{
if(comment||lineComment)
{
prJComment(str);
}elseif(stringlit)
{
prStringLit(str);
}else
{
out.append("<FONTcolor=black>"+str+"</FONT>
");
}
}
publicstaticvoidprNumber(Stringstr)
{
if(comment||lineComment)
{
prJComment(str);
}elseif(stringlit)
{
prStringLit(str);
}else
{
out.append("<FONTcolor=blue>"+str+"</FONT>
");
}
}
publicstaticvoidprStringLit(Stringstr)
{
out.append(str+"
");
}
publicstaticvoidprHead(booleanstart)
{
if(start)
{
out.append("<HEAD>");
out.append("
");
}else
{
out.append("</HEAD>");
out.append("
");
}
}
publicstaticvoidprBody(booleanstart)
{
if(start)
{
out.append("<BODYbgcolor=whitecolor=red>");
out.append("
");
out.append("<tt><FONTcolor=red>");
out.append("
");
}else
{
out.append("</FONT></tt>");
out.append("
");
out.append("</BODY>");
out.append("
");
}
}
publicstaticvoidprComment(booleanstart)
{
if(start)
{
out.append("<!--");
out.append("
");
}else
{
out.append("-->");
out.append("
");
}
}
publicstaticvoidprHtml(booleanstart)
{
if(start)
{
out.append("<HTML>");
out.append("
");
}else
{
out.append("</HTML>");
out.append("
");
}
}
publicstaticvoidprBr(booleanstart)
{
if(start)
{
out.append("<BR>");
out.append("
");
}else
{
out.append("<BR>");
out.append("
");
}
out.append(tab);
}
publicstaticvoidprP(booleanstart)
{
if(start)
{
out.append("<P>");
out.append("
");
}else
{
out.append("</P>");
out.append("
");
}
}
publicstaticvoidprTable(booleanstart)
{
if(start)
{
out.append("<TABLE>");
out.append("
");
}else
{
out.append("</TABLE>");
out.append("
");
}
}
publicstaticvoidprTr(booleanstart)
{
if(start)
{
out.append("<TR>");
out.append("
");
}else
{
out.append("</TR>");
out.append("
");
}
}
publicstaticvoidprTd(booleanstart)
{
if(start)
{
out.append("<TD>");
out.append("
");
}else
{
out.append("</TD>");
out.append("
");
}
}
publicstaticvoidprStringOne(booleanstart)
{
if(comment||lineComment)
{
prJComment("");
}elseif(start)
{
out.append("<FONTcolor=green>
");
stringlit=true;
}else
{
out.append("</FONT>
");
stringlit=false;
}
}
publicstaticvoidprStringTwo(booleanstart)
{
if(comment||lineComment)
{
prJComment(""");
}elseif(start)
{
out.append("<FONTcolor=green>"
");
stringlit=true;
stringlit2=true;
}else
{
out.append(""</FONT>
");
stringlit=false;
stringlit2=false;
}
}
publicstaticvoidmain(String[]args)
{
if(args.length<2)
{
System.out.println("
毛病:参数不敷!");
System.out.println("java2html[源文件][将天生文件名]");
}
else
{
FileInputStreamfile;
StreamTokenizerst;
StringhtmlFile=args[1];
booleanisVar=false;
putHtmlputhtml=newputHtml();
booleanfirstOfComment=false;
intb=8;
inta=10/b;
try
{
file=newFileInputStream(args[0]);
Readerr=newBufferedReader(newInputStreamReader(file));
st=newStreamTokenizer(r);
st.eolIsSignificant(true);
st.ordinaryChar(");
st.ordinaryChar(/);
st.ordinaryChar();
st.ordinaryChar(.);
st.ordinaryChar();
prHtml(START);
prHead(START);
prTitle(args[0]);
prHead(END);
prBody(START);
<P>while(st.nextToken()!=StreamTokenizer.TT_EOF)
{
switch(st.ttype)
{
caseStreamTokenizer.TT_WORD:
if(firstOfComment)
{
if((!comment&&!lineComment))prOperator("/");
}
firstOfComment=false;
if(primitives.contains(st.sval))
{
prPrimitive(st.sval);
isVar=true;
backslash=false;
break;
}
if(flow.contains(st.sval))
{
isVar=false;
prNumber(st.sval);
backslash=false;
break;
}
if(resWords.contains(st.sval))
{
isVar=false;
prResWord(st.sval);
backslash=false;
break;
}
if(varList.contains(st.sval))
{
isVar=false;
prVar(st.sval);
backslash=false;
break;
}
if(isVar&&!(varList.contains(st.sval)))
{
varList.add(st.sval);
prVar(st.sval);
}else
{
prNormal(st.sval);
}
backslash=false;
break;
caseStreamTokenizer.TT_EOL:
isVar=false;
if(firstOfComment)
{
prOperator("/");
firstOfComment=false;
}
firstOfComment=false;
lineComment=false;
prBr(START);
backslash=false;
break;
caseStreamTokenizer.TT_NUMBER:
isVar=false;
if(firstOfComment)
{
prOperator("/");
firstOfComment=false;
}
firstOfComment=false;
if(String.valueOf((char)st.ttype).equals("."))
{
prFlow(".");
backslash=false;
break;
}
prNumber(newDouble(st.nval).toString());
backslash=false;
break;
default:
isVar=false;
if(operators.contains(String.valueOf((char)st.ttype)))
{
if(firstOfComment)
{
if(comment)
{
//therehasbeenastar,waitingforslash
if(String.valueOf((char)st.ttype).equals("/"))
{
firstOfComment=false;
prJComment("*/");
comment=false;
backslash=false;
firstOfComment=false;
break;
}elsefirstOfComment=false;
}else
{
//therehasbeenaslash,waitingforslashorstar
if(String.valueOf((char)st.ttype).equals("/"))
{
if(!stringlit)
{
lineComment=true;
prJComment("//");
}else
{
lineComment=false;
prNormal("//");
}
firstOfComment=false;
comment=false;
backslash=false;
break;
}elseif(String.valueOf((char)st.ttype).equals("*"))
{
if(!stringlit)
{
comment=true;
prJComment("/*");
}else
{
comment=false;
prNormal("/*");
}
firstOfComment=false;
lineComment=false;
backslash=false;
break;
}else
{
firstOfComment=false;
if(!lineComment)prOperator("/");
prOperator(String.valueOf((char)st.ttype));
backslash=false;
break;
}
}
}else
{
if(comment)
{
//waitingforstar
if(String.valueOf((char)st.ttype).equals("*"))
{
firstOfComment=true;
backslash=false;
break;
}elsefirstOfComment=false;
}else
{
//waitingforslash
if(String.valueOf((char)st.ttype).equals("/"))
{
firstOfComment=true;
backslash=false;
break;
}else
{
firstOfComment=false;
prOperator(String.valueOf((char)st.ttype));
backslash=false;
break;
}
}
}
}
if(String.valueOf((char)st.ttype).equals("""))
{
if(firstOfComment)
{
if(!(comment||lineComment))prOperator("/");
firstOfComment=false;
}
if(!backslash)prStringTwo(!stringlit);
elseprNormal(""");
backslash=false;
break;
}
if(String.valueOf((char)st.ttype).equals(""))
{
if(firstOfComment)
{
prOperator("/");
firstOfComment=false;
}
prNormal("");
backslash=!backslash;
break;
}
if(String.valueOf((char)st.ttype).equals(""))
{
if(firstOfComment)
{
prOperator("/");
firstOfComment=false;
}
if(!backslash&&!stringlit2)prStringOne(!stringlit);
elseprNormal("");
backslash=false;
break;
}
if(String.valueOf((char)st.ttype).equals(";"))
{
if(firstOfComment)
{
prOperator("/");
&nbs
轮性能微软曾做过一个例子,就是同一个项目用java和.net来作,结果开发周期,.net是java的一半,性能java是.net的十分之一,代码量java是.net的三倍。呵呵,这说明了什么,.net的全方位比java好。但是有的人说.net不能跨平台,这个问题我和我同学曾讨论过,都认为微软的.net很可能早都可以跨平台了,但是微软为了保护他们的操作系统,所以才没有推出跨平台的.net,只是推出了跨语言的.net, |
|