2011-09-23 181 views
0

我在將值設置爲SoyFileSupplier列表時遇到問題,列表中應該有類型文件的值,通過傳遞一個soyFileSupplier列表來將soyfilesetParse類用於解析,將值設置爲。文件(sample.soy)將值設置爲列表

The sample code is as below: 

public class test { 
    main() { 
      soyTree=parseSoyFiles(soyFileSuppliers); 
    } 
} 

調用類是:

public class soyFileSetParse { 
    public static SoyFileSetNode parseSoyFiles(List<SoyFileSupplier> soyFileSuppliers) 
     throws SoySyntaxException { 

     IdGenerator nodeIdGen = new IntegerIdGenerator(); 
     SoyFileSetNode soyTree = new SoyFileSetNode(nodeIdGen.genStringId(), nodeIdGen); 

     for (SoyFileSupplier soyFileSupplier : soyFileSuppliers) { 
      soyTree.addChild(parseSoyFileHelper(soyFileSupplier, nodeIdGen)); 
     } 

     return soyTree; 
    } 
} 

設置爲文件類型:

public class SoyFileSupplier { 
    /** 
    * Creates a new {@code SoyFileSupplier} given a {@code File}. 
    * 
    * @param inputFile The Soy file. 
    */ 
    public SoyFileSupplier(File inputFile) { 
     this(Files.newReaderSupplier(inputFile, Charsets.UTF_8), inputFile.getPath()); 
    } 

我不明白我做錯了什麼。

+0

您的問題是什麼? – Saket

回答

1

由於parseSoyFiles(...)soyFileSetParse類的static方法,你需要用類名來調用它,而無需創建類的實例,如

ClassName.methodName(args) 

因此,您的main()方法的內容應如下所示

SoyFileSetNode soyTree = soyFileSetParse.parseSoyFiles(soyFileSuppliers); 
+1

並且還使用'public static void main(String [] args)'作爲main方法。並初始化_soyfileSuppliers_'SoyFileSupplier soyFileSuppliers = new SoyFileSupplier(new File(「path/to/file」));'。不要提及下面的java案例約定。 –

+0

@AnonyAccioly,是的 - 代碼片段有很多錯誤。 :/ – mrkhrts

相關問題