001 /* 002 * mesopotamia-java @mesopotamia.version@ 003 * Multilingual parser and repository. 004 * Copyright (C) 2005 Hammurapi Group 005 * 006 * This program is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU Lesser General Public 008 * License as published by the Free Software Foundation; either 009 * version 2 of the License, or (at your option) any later version. 010 * 011 * This program is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 * Lesser General Public License for more details. 015 * 016 * You should have received a copy of the GNU Lesser General Public 017 * License along with this library; if not, write to the Free Software 018 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 019 * 020 * URL: http://http://www.hammurapi.biz 021 * e-Mail: support@hammurapi.biz 022 */ 023 024 package org.mesopotamia.lang.java.javadoc; 025 026 import java.util.ArrayList; 027 import java.util.Collections; 028 import java.util.List; 029 030 import org.mesopotamia.MesopotamiaRuntimeException; 031 032 import antlr.collections.AST; 033 034 /** 035 * @author Pavel Vlasov 036 * @version $Revision: 1.2 $ 037 */ 038 public class Tag { 039 private String name; 040 private List<String> informalSpecification=new ArrayList<String>(); 041 private List<FormalSentence> formalSpecification=new ArrayList<FormalSentence>(); 042 private String informalText; 043 044 public Tag(AST ast) { 045 for (AST node=ast.getFirstChild(); node!=null; node=node.getNextSibling()) { 046 switch (node.getType()) { 047 case JavaDocTokenTypes.TAG: 048 name=node.getFirstChild().getText(); 049 break; 050 case JavaDocTokenTypes.INFORMAL: 051 readInformalSpecification(node); 052 break; 053 case JavaDocTokenTypes.FORMAL: 054 readFormalSpecification(node); 055 break; 056 default: 057 throw new MesopotamiaRuntimeException("Invalid javadoc token type: "+ast.getType()); 058 059 } 060 } 061 } 062 063 /** 064 * @param ast 065 */ 066 private void readInformalSpecification(AST ast) { 067 StringBuffer buf=new StringBuffer(); 068 for (AST node=ast.getFirstChild(); node!=null; node=node.getNextSibling()) { 069 informalSpecification.add(node.getText()); 070 if (buf.length()!=0) { 071 buf.append(" "); 072 } 073 buf.append(node.getText()); 074 } 075 informalText=buf.toString(); 076 } 077 078 /** 079 * @param ast 080 */ 081 private void readFormalSpecification(AST ast) { 082 for (AST node=ast.getFirstChild(); node!=null; node=node.getNextSibling()) { 083 formalSpecification.add(new FormalSentence(node)); 084 } 085 } 086 087 public String getName() { 088 return name; 089 } 090 091 public List<String> getInformalSpecification() { 092 return Collections.unmodifiableList(informalSpecification); 093 } 094 095 public List<FormalSentence> getFormalSpecification() { 096 return Collections.unmodifiableList(formalSpecification); 097 } 098 099 public String getInformalSpecificationAsString() { 100 return informalText; 101 } 102 }