⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 parser.java

📁 linux下建立JAVA虚拟机的源码KAFFE
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* gnu.classpath.tools.gjdoc.Parser   Copyright (C) 2001, 2005 Free Software Foundation, Inc.   This file is part of GNU Classpath.   GNU Classpath is free software; you can redistribute it and/or modify   it under the terms of the GNU General Public License as published by   the Free Software Foundation; either version 2, or (at your option)   any later version.    GNU Classpath is distributed in the hope that it will be useful, but   WITHOUT ANY WARRANTY; without even the implied warranty of   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU   General Public License for more details.   You should have received a copy of the GNU General Public License   along with GNU Classpath; see the file COPYING.  If not, write to the   Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA   02111-1307 USA. */package gnu.classpath.tools.gjdoc;import java.io.*;import java.nio.ByteBuffer;import java.nio.CharBuffer;import java.nio.charset.Charset;import java.nio.charset.CharsetDecoder;import java.nio.charset.CoderResult;import java.nio.charset.CodingErrorAction;import java.util.*;import com.sun.javadoc.*;import gnu.classpath.tools.IOToolkit;import gnu.classpath.tools.NotifyingInputStreamReader;import gnu.classpath.tools.MalformedInputListener;import gnu.classpath.tools.MalformedInputEvent;   class IgnoredFileParseException extends ParseException    {      // marker exception   }   abstract class SourceComponent {      abstract int match(char[] source, int index) throws ParseException;      int process(Parser parser, char[] source, int startIndex, int endIndex) throws ParseException, IOException {	 return endIndex;      }      int getEndIndex(char[] source, int endIndex) throws ParseException {	 return endIndex;      }   }   abstract class BlockSourceComponent extends SourceComponent {      int getEndIndex(char[] source, int endIndex) throws ParseException {	 return Parser.skipExpression(source, endIndex, 1, '\0');      }   }   class Whitespace extends SourceComponent {      int match(char[] source, int index) {	 int rc=index;	 int slen=source.length;	 while (rc<slen && Parser.WHITESPACE.indexOf(source[rc])>=0) ++rc;	 return (rc!=index) ? rc : -1;      }   }   class BracketClose extends SourceComponent {      int match(char[] source, int index) {	 if (source[index]=='}') {	    return index+1;	 }	 else {	    return -1;	 }      }      int process(Parser parser, char[] source, int startIndex, int endIndex) throws ParseException, IOException {	 parser.classClosed();	 return endIndex;      }   }   class CommentComponent extends SourceComponent {      int match(char[] source, int index) throws ParseException {	 if (index+1<source.length && source[index]=='/' && source[index+1]=='*') {	    for (index+=2; index+1<source.length; ++index) {	       if (source[index]=='*' && source[index+1]=='/')		  return index+2;	    }	    throw new ParseException("unexpected end of input");	 }	 return -1;      }      int process(Parser parser, char[] source, int startIndex, int endIndex) {	 if (source[startIndex+0]=='/' 	     && source[startIndex+1]=='*' 	     && source[startIndex+2]=='*') {	    parser.setLastComment(new String(source, startIndex, endIndex-startIndex));	 }         else if (null == parser.getBoilerplateComment() && Main.getInstance().isCopyLicenseText()) {            String boilerplateComment = new String(source, startIndex + 2, endIndex-startIndex - 4);            if (boilerplateComment.toLowerCase().indexOf("copyright") >= 0) {               parser.setBoilerplateComment(boilerplateComment);            }         }	 return endIndex;      }   }   class SlashSlashCommentComponent extends SourceComponent {      int match(char[] source, int index) {	 if (index+1<source.length && source[index]=='/' && source[index+1]=='/') {	    index+=2;	    while (index<source.length && source[index]!='\n')	       ++index;	    return index;	 }	 else {	    return -1;	 }      }   }   class EmptyStatementComponent extends SourceComponent {      int match(char[] source, int index) {         while (index < source.length                && Parser.isWhitespace(source[index])) {            ++ index;         }         if (index < source.length && source[index] == ';') {            return index+1;         }         else {            return -1;         }      }   }   class ImportComponent extends SourceComponent {      int match(char[] source, int index) {	 if (index+7<source.length) {	    if (source[index+0]=='i' 		&& source[index+1]=='m'		&& source[index+2]=='p'		&& source[index+3]=='o'		&& source[index+4]=='r'		&& source[index+5]=='t'		&& Parser.WHITESPACE.indexOf(source[index+6])>=0) {	       for (index+=7; index<source.length && source[index]!=';'; ++index)		  ;	       return index+1;	    }	 }	 return -1;      }      int process(Parser parser, char[] source, int startIndex, int endIndex) throws ParseException, IOException {	 String importString=new String(source,startIndex+7,endIndex-startIndex-7-1).trim();	 parser.importEncountered(importString);     	 return endIndex;      }   }   class PackageComponent extends SourceComponent {      int match(char[] source, int index) {	 if (index+10<source.length) {	    if (source[index+0]=='p' 		&& source[index+1]=='a'		&& source[index+2]=='c'		&& source[index+3]=='k'		&& source[index+4]=='a'		&& source[index+5]=='g'		&& source[index+6]=='e'		&& Parser.WHITESPACE.indexOf(source[index+7])>=0) {	       for (index+=7; index<source.length && source[index]!=';'; ++index)		  ;	       return index+1;	    }	 }	 return -1;      }      int process(Parser parser, char[] source, int startIndex, int endIndex) {	 String packageName=new String(source,startIndex+8,endIndex-startIndex-8-1).trim();	 parser.packageOpened(packageName);	 return endIndex;      }   }   class FieldComponent extends SourceComponent {      int match(char[] source, int index) throws ParseException {	 boolean isField=false;	 final int STATE_NORMAL=1;	 final int STATE_SLASHC=2;	 final int STATE_STARC=3;	 final int STATE_FIELDVAL=4;	 final int STATE_STRING=5;	 final int STATE_SINGLEQUOTED=6;	 final int STATE_STRING_BS=7;	 final int STATE_SINGLEQUOTED_BS=8;	 int state=STATE_NORMAL;         int prevState=STATE_NORMAL;         int fieldValueLevel = 0;	 for (; index<source.length && !isField; ++index) {	    if (state==STATE_STARC) {	       if (index<source.length-1 && source[index]=='*' && source[index+1]=='/') {		  ++index;		  state=prevState;	       }	    }	    else if (state==STATE_SLASHC) {	       if (source[index]=='\n') {		  state=prevState;	       }	    }	    else if (state==STATE_STRING) {	       if (source[index]=='\\') {		  state=STATE_STRING_BS;	       }	       else if (source[index]=='\"') {		  state=prevState;	       }	    }	    else if (state==STATE_STRING_BS) {               state=STATE_STRING;            }	    else if (state==STATE_SINGLEQUOTED) {	       if (source[index]=='\\') {		  state=STATE_SINGLEQUOTED_BS;	       }	       else if (source[index]=='\'') {		  state=prevState;	       }	    }	    else if (state==STATE_SINGLEQUOTED_BS) {               state=STATE_SINGLEQUOTED;            }            else if (state==STATE_FIELDVAL) {               if (source[index]=='/') {                  if (index<source.length-1 && source[index+1]=='*') {                     state=STATE_STARC;                      ++index;                  }                  else if (index<source.length-1 && source[index+1]=='/') {                     state=STATE_SLASHC;                      ++index;                  }               }               else if (source[index]=='{') {                  ++ fieldValueLevel;               }               else if (source[index]=='}') {                  -- fieldValueLevel;               }               else if (source[index]=='\"') {                  state=STATE_STRING;               }               else if (source[index]=='\'') {                  state=STATE_SINGLEQUOTED;               }               else if (source[index]==';' && 0 == fieldValueLevel) {                  isField=true;                  break;               }            }	    else switch (source[index]) {	    case '/': 	       if (index<source.length-1 && source[index+1]=='*') {		  state=STATE_STARC; 		  ++index;	       }	       else if (index<source.length-1 && source[index+1]=='/') {		  state=STATE_SLASHC; 		  ++index;	       }	       break;	    case '{':  // class	    case '(':  // method	       return -1;	    case '=':  // field               state=STATE_FIELDVAL;               prevState=state;               continue;	    case ';':  // field	       isField=true;	       break;	    }	    if (isField) break;	 }	 if (!isField || index==source.length) {	    return -1;	 }	 //System.err.println("char is "+source[index]);	 if (source[index]!=';') {	    index=Parser.skipExpression(source, index, 0, ';');	 }	 return index+1;      }      int process(Parser parser, char[] source, int startIndex, int endIndex) {	 //Debug.log(9,"found package statement: \""+str+"\"");	 //Debug.log(9,"found function component: '"+str+"'");	 //xxx(new FieldDocImpl(ctx.classDoc, ctx.classDoc.containingPackage(), 0, false, false));	 // Ignore superfluous semicoli after class definition	 if (endIndex-startIndex<=1) return endIndex;	 //assert (parser.ctx!=null);	 Collection fields=FieldDocImpl.createFromSource(parser.ctx.classDoc, 							 parser.ctx.classDoc.containingPackage(), 							 source, startIndex, endIndex);	 for (Iterator it=fields.iterator(); it.hasNext(); ) {	    FieldDocImpl field=(FieldDocImpl)it.next();	    boolean fieldHasSerialTag=!field.isTransient() && !field.isStatic(); //field.hasSerialTag();	    if ((field.isIncluded() || fieldHasSerialTag) && parser.getAddComments()) {	       field.setRawCommentText(parser.getLastComment());	    }            parser.ctx.fieldList.add(field);	    if (field.isIncluded()) {	       parser.ctx.filteredFieldList.add(field);	    }	    if (fieldHasSerialTag) {	       parser.ctx.sfieldList.add(field);	    }	 }	 parser.setLastComment(null);	 return endIndex;      }      }   class FunctionComponent extends BlockSourceComponent {      int getEndIndex(char[] source, int endIndex) throws ParseException {	 if (source[endIndex-1]==';') {	    return endIndex;	 }	 else {	    return super.getEndIndex(source, endIndex);	 }      }      int process(Parser parser, char[] source, int startIndex, int endIndex) throws IOException, ParseException {	 //ctx.fieldList.add(FieldDocImpl.createFromSource(source, startIndex, endIndex));	 //System.out.println("function match '"+new String(source,startIndex,endIndex-startIndex)+"'");	 ExecutableMemberDocImpl execDoc=MethodDocImpl.createFromSource(parser.ctx.classDoc, 									parser.ctx.classDoc.containingPackage(), 									source, startIndex, endIndex);	 if (parser.getAddComments())	    execDoc.setRawCommentText(parser.getLastComment());	 parser.setLastComment(null);         if (execDoc.isMethod()) {            parser.ctx.methodList.add(execDoc);            if (execDoc.isIncluded()) {               parser.ctx.filteredMethodList.add(execDoc);            }         }         else {            parser.ctx.constructorList.add(execDoc);            if (execDoc.isIncluded()) {               parser.ctx.filteredConstructorList.add(execDoc);            }         }	 if (execDoc.isMethod() 		  && (execDoc.name().equals("readObject")		      || execDoc.name().equals("writeObject")		      || execDoc.name().equals("readExternal")		      || execDoc.name().equals("writeExternal")		      || execDoc.name().equals("readResolve"))) {           // FIXME: add readExternal here?	    parser.ctx.maybeSerMethodList.add(execDoc);	 }	 return endIndex;      }      int match(char[] source, int index) {	 boolean isFunc=false;	 final int STATE_NORMAL=1;	 final int STATE_SLASHC=2;	 final int STATE_STARC=3;	 int state=STATE_NORMAL;	 for (; index<source.length && !isFunc; ++index) {	    if (state==STATE_STARC) {	       if (source[index]=='*' && source[index+1]=='/') {		  ++index;		  state=STATE_NORMAL;	       }	    }	    else if (state==STATE_SLASHC) {	       if (source[index]=='\n') {		  state=STATE_NORMAL;	       }	    }	    else switch (source[index]) {	    case '/': 	       if (source[index+1]=='*') {		  state=STATE_STARC; 		  ++index;	       }	       else if (source[index+1]=='/') {		  state=STATE_SLASHC; 		  ++index;	       }	       break;	    case '=':  // field	    case ';':  // field	    case '{':  // class	       return -1;	    case '(':	       isFunc=true;	       break;	    }	    if (isFunc) break;	 }	 if (!isFunc || index==source.length)	    return -1;	 for (; index<source.length && (state!=STATE_NORMAL || (source[index]!='{' && source[index]!=';')); ++index)	    if (state==STATE_SLASHC && source[index]=='\n') {	       state=STATE_NORMAL;	    }	    else if (index<source.length-1) {	       if (state==STATE_STARC) {		  if (source[index]=='*' && source[index+1]=='/') {		     state=STATE_NORMAL;		  }	       }	       else {		  if (source[index]=='/' && source[index+1]=='*') {		     state=STATE_STARC;		  }		  else if (source[index]=='/' && source[index+1]=='/') {		     state=STATE_SLASHC;		  }	       }	    }	 return index+1;      }      }   class StaticBlockComponent extends BlockSourceComponent {      int process(Parser parser, char[] source, int startIndex, int endIndex) {	 //Debug.log(9,"found package statement: \""+str+"\"");	 //Debug.log(9,"found function component: '"+str+"'");	 parser.setLastComment(null);	 return endIndex;      }         int match(char[] source, int index) {	 if (source[index]=='{') return index+1;	 if (index+7<source.length) {	    if (source[index+0]=='s' 		&& source[index+1]=='t'		&& source[index+2]=='a'

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -