use of org.eclipse.xtext.xtext.ui.wizard.project.XtextProjectInfo in project xtext-eclipse by eclipse.
the class GrammarGeneratorTest method checkGeneratedGrammarIsValid.
private void checkGeneratedGrammarIsValid(List<String> ePackageURIs) throws IOException {
for (String nsURI : ePackageURIs) {
System.out.print(nsURI);
EPackage ePackage = EPackage.Registry.INSTANCE.getEPackage(nsURI);
XtextProjectInfo xtextProjectInfo = new XtextProjectInfo();
Set<EPackage> ePackages = new HashSet<EPackage>();
if (!addImportedEPackages(ePackage, ePackages)) {
System.out.println("...skipping");
} else {
List<EPackageInfo> ePackageInfos = Lists.newArrayList(Iterables.transform(ePackages, new Function<EPackage, EPackageInfo>() {
@Override
public EPackageInfo apply(EPackage from) {
return new EPackageInfo(from, URI.createURI(from.getNsURI()), null, null, null);
}
}));
xtextProjectInfo.getEcore2Xtext().getEPackageInfos().addAll(ePackageInfos);
String languageName = "org.eclipse.xtext.xtext.ui.tests." + ePackage.getName();
xtextProjectInfo.getLanguage().setName(languageName);
String grammarFileName = languageName.replaceAll("\\.", "/") + ".xtext";
String xtextGrammar = createGrammar(xtextProjectInfo).toString();
ResourceSet resourceSet = new XtextResourceSet();
Resource xtextResource = resourceSet.createResource(URI.createFileURI(grammarFileName));
xtextResource.load(new StringInputStream(xtextGrammar), null);
checkErrors(ePackage, xtextResource, xtextGrammar);
if (!WARNING_PACKAGE_NS_URIS.contains(ePackage.getNsURI())) {
assertTrue("Warnings in grammar for " + ePackage.getNsURI(), xtextResource.getWarnings().isEmpty());
}
System.out.println(" ...OK");
}
}
}
use of org.eclipse.xtext.xtext.ui.wizard.project.XtextProjectInfo in project xtext-eclipse by eclipse.
the class Ecore2XtextGenerator method createXtextProjectInfo.
private void createXtextProjectInfo(Issues issues) {
if (xtextProjectInfo == null) {
xtextProjectInfo = new XtextProjectInfo();
List<EPackageInfo> ePackageInfos = new ArrayList<EPackageInfo>();
EClass rootElementClass = null;
for (Iterator<Notifier> i = resourceSet.getAllContents(); i.hasNext(); ) {
Notifier next = i.next();
if (next instanceof EPackage) {
EPackage ePackage = (EPackage) next;
ePackageInfos.add(new EPackageInfo(ePackage, URI.createURI(ePackage.getNsURI()), null, null, null));
if (rootElementClass == null) {
EClassifier rootElementClassifier = ePackage.getEClassifier(rootElementClassName);
if (rootElementClassifier instanceof EClass) {
rootElementClass = (EClass) rootElementClassifier;
}
}
}
}
if (ePackageInfos.isEmpty()) {
issues.addError("No EPackages found");
} else {
xtextProjectInfo.getEcore2Xtext().setDefaultEPackageInfo(ePackageInfos.get(0));
}
if (rootElementClass == null) {
issues.addError("No rootElement EClass " + rootElementClassName + " found");
}
if (languageName == null) {
issues.addError("languageName must be set");
}
xtextProjectInfo.getLanguage().setName(languageName);
xtextProjectInfo.getEcore2Xtext().getEPackageInfos().addAll(ePackageInfos);
xtextProjectInfo.getEcore2Xtext().setRootElementClass(rootElementClass);
}
}
use of org.eclipse.xtext.xtext.ui.wizard.project.XtextProjectInfo in project xtext-eclipse by eclipse.
the class NewXtextProjectFromEcoreWizard method getProjectInfo.
@Override
protected IProjectInfo getProjectInfo() {
XtextProjectInfo projectInfo = (XtextProjectInfo) super.getProjectInfo();
RuntimeProjectDescriptor runtimeProjectDescriptor = projectInfo.getRuntimeProject();
runtimeProjectDescriptor.setWithPluginXml(false);
Ecore2XtextConfiguration ecore2Xtext = projectInfo.getEcore2Xtext();
ecore2Xtext.getEPackageInfos().addAll(ePackageSelectionPage.getEPackageInfos());
ecore2Xtext.setRootElementClass(ePackageSelectionPage.getRootElementClass());
ecore2Xtext.setDefaultEPackageInfo(ePackageSelectionPage.getDefaultEPackageInfo());
return projectInfo;
}
Aggregations