Search in sources :

Example 1 with XtextProjectInfo

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");
        }
    }
}
Also used : Function(com.google.common.base.Function) StringInputStream(org.eclipse.xtext.util.StringInputStream) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) XtextProjectInfo(org.eclipse.xtext.xtext.ui.wizard.project.XtextProjectInfo) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) EPackageInfo(org.eclipse.xtext.xtext.wizard.EPackageInfo) EPackage(org.eclipse.emf.ecore.EPackage) HashSet(java.util.HashSet)

Example 2 with XtextProjectInfo

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);
    }
}
Also used : EClass(org.eclipse.emf.ecore.EClass) XtextProjectInfo(org.eclipse.xtext.xtext.ui.wizard.project.XtextProjectInfo) ArrayList(java.util.ArrayList) EClassifier(org.eclipse.emf.ecore.EClassifier) EPackageInfo(org.eclipse.xtext.xtext.wizard.EPackageInfo) Notifier(org.eclipse.emf.common.notify.Notifier) EPackage(org.eclipse.emf.ecore.EPackage)

Example 3 with XtextProjectInfo

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;
}
Also used : Ecore2XtextConfiguration(org.eclipse.xtext.xtext.wizard.Ecore2XtextConfiguration) XtextProjectInfo(org.eclipse.xtext.xtext.ui.wizard.project.XtextProjectInfo) RuntimeProjectDescriptor(org.eclipse.xtext.xtext.wizard.RuntimeProjectDescriptor)

Aggregations

XtextProjectInfo (org.eclipse.xtext.xtext.ui.wizard.project.XtextProjectInfo)3 EPackage (org.eclipse.emf.ecore.EPackage)2 EPackageInfo (org.eclipse.xtext.xtext.wizard.EPackageInfo)2 Function (com.google.common.base.Function)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Notifier (org.eclipse.emf.common.notify.Notifier)1 EClass (org.eclipse.emf.ecore.EClass)1 EClassifier (org.eclipse.emf.ecore.EClassifier)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)1 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)1 StringInputStream (org.eclipse.xtext.util.StringInputStream)1 Ecore2XtextConfiguration (org.eclipse.xtext.xtext.wizard.Ecore2XtextConfiguration)1 RuntimeProjectDescriptor (org.eclipse.xtext.xtext.wizard.RuntimeProjectDescriptor)1