nescfile.java

来自「plugin for eclipse」· Java 代码 · 共 122 行

JAVA
122
字号
/*
 * Created on May 9, 2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package isis.anp.nesc.ot;

import isis.anp.common.TNode;
import isis.anp.nesc.tinydoc.TinyDoc;
import isis.anp.nesc.tinydoc.TinyDocFactory;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import antlr.CommonHiddenStreamToken;
import antlr.RecognitionException;

/**
 * @author sallai
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public abstract class NesCFile {
	TNode defNode;
	ArrayList includeFiles = new ArrayList();
	
	/**
	 * @return Returns the defNode.
	 */
	public TNode getDefNode() {
		return defNode;
	}
	/**
	 * @param defNode The defNode to set.
	 */
	public void setDefNode(TNode defNode) {
		this.defNode = defNode;
	}
	
	public void addIncludeFile(NesCIncludeFile f) {
		includeFiles.add(f);
	}

	public void addIncludeFiles(List list) {
		includeFiles.addAll(list);
	}
	
	public String getFileName() {
		if(defNode.getAttribute("source") != null) {
			return (String) defNode.getAttribute("source");
		} else {
			return null;
		}
	}
	
	public String getNesCName() {
		String fn = this.getFileName();
		int dotPos = fn.lastIndexOf(".");
		int slashPos = fn.lastIndexOf("/");
		int backSlashPos = fn.lastIndexOf("\\");
		int nameStartPos;
		if(slashPos>backSlashPos) {
			nameStartPos = slashPos;
		} else {
			nameStartPos = backSlashPos;
		}
		if(dotPos>0) {
			return fn.substring(nameStartPos+1, dotPos);
		} else {
			return fn.substring(nameStartPos+1);
		}
	}
	
	public String getTinyDocText() {
	    if(this.defNode==null) return null;
	    TNode nextRealNode = this.defNode.getNextRealNode();
	    if(nextRealNode==null) return null;
	    
	    // return the TinyDoc comment preceding the first real node
	    CommonHiddenStreamToken tinyDocTok = nextRealNode.getHiddenBefore();
	    if(tinyDocTok==null) return null;
	    return tinyDocTok.getText();
	}
	
	public TinyDoc getTinyDoc() {
	    String tinyDocText = getTinyDocText();
	    if(tinyDocText == null) return null;
	    
	    try {
            return TinyDocFactory.parse(tinyDocText);
        } catch (RecognitionException e) {
            System.out.println("Error parsing TinyDoc: " + tinyDocText);
            return null;
        }
	}
	
	public void outline(Outline o) {
//		String doc = getTinyDocText();
	    String doc = null;
	    TinyDoc tinyDoc = getTinyDoc();
	    if(tinyDoc !=null) doc = tinyDoc.toString();
		if(doc!=null) { 
		    o.addTabs();
		    o.append(doc);
		    o.addNewLine();
		}

		Iterator i = this.includeFiles.iterator();			
		while (i.hasNext()) {
			NesCIncludeFile inc = (NesCIncludeFile) i.next();
			o.addTabs();
			o.append("includes ");
			o.append(inc.getNesCName());
			o.append(";\n");
		}
		
	}
}

⌨️ 快捷键说明

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