you need to use injection to obtain the parsehelper e.g.
import org.eclipse.xtext.testing.util.ParseHelper;
import org.xtext.example.mydsl5.MyDslStandaloneSetup;
import org.xtext.example.mydsl5.myDsl.Model;
import com.google.inject.Inject;
import com.google.inject.Injector;
public class Main {
public static void main(String[] args) throws Exception {
Injector injector = new MyDslStandaloneSetup().createInjectorAndDoEMFRegistration();
Main main = injector.getInstance(Main.class);
System.out.println(main.doGetModel("Hello World!"));
}
@Inject ParseHelper<Model> parserHelper;
public Model doGetModel(String content) throws Exception {
return parserHelper.parse(content);
}
}
or
import org.eclipse.xtext.testing.util.ParseHelper;
import org.xtext.example.mydsl5.MyDslStandaloneSetup;
import org.xtext.example.mydsl5.myDsl.Model;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
public class Main {
public static void main(String[] args) throws Exception {
System.out.println(doGetModel("Hello World!"));
}
public static Model doGetModel(String content) throws Exception {
Injector injector = new MyDslStandaloneSetup().createInjectorAndDoEMFRegistration();
ParseHelper<Model> parserHelper = injector.getInstance(Key.get(new TypeLiteral<ParseHelper<Model>>() {}));
return parserHelper.parse(content);
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…