2011-09-23 139 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

相关问题