微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

org.eclipse.xtext.GeneratedMetamodel的实例源码

项目:xtext-extras    文件EMFGeneratorFragment.java   
@Override
public String[] getExportedPackagesRt(Grammar grammar) {
    List<Generatedmetamodel> typeSelect = org.eclipse.xtext.EcoreUtil2.typeSelect(
            grammar.getmetamodelDeclarations(),Generatedmetamodel.class);
    Set<String> exportedPackages = new LinkedHashSet<String>();
    if (modelPluginID == null) {
        for (Generatedmetamodel generatedmetamodel : typeSelect) {
            final String modelPackage = Strings.skipLastToken(
                    getGeneratedEPackageName(grammar,generatedmetamodel.getEPackage()),".");
            exportedPackages.add(modelPackage);
            exportedPackages.add(modelPackage + ".impl");
            exportedPackages.add(modelPackage + ".util");
        }
    }
    return exportedPackages.toArray(new String[exportedPackages.size()]);
}
项目:Vitruv    文件ReactionsLanguageXtext2EcorePostProcessor.java   
@Override
public void process(Generatedmetamodel metamodel) {
    if (!metamodel.getName().equals("reactionsLanguage"))
        return;

    final EPackage ePackage = metamodel.getEPackage();
    final EClass reactionsSegmentEClass = getEClass(ePackage,"ReactionsSegment");
    final EClass reactionEClass = getEClass(ePackage,"Reaction");
    final EClass effectEClass = getEClass(ePackage,"Routine");

    // Add an opposite reference for the metamodel pair to the reaction
    final EReference reactionsSegmentReactionsReference = (EReference)reactionsSegmentEClass.getEStructuralFeature("reactions");
    addReactionsSegmentEReference(reactionEClass,reactionsSegmentReactionsReference);

    final EReference reactionsSegmentEffectsReference = (EReference)reactionsSegmentEClass.getEStructuralFeature("routines");
    addReactionsSegmentEReference(effectEClass,reactionsSegmentEffectsReference);
}
项目:xtext-core    文件XtendXtext2EcorePostProcessor.java   
@Override
public void process(Generatedmetamodel metamodel) {
    Resource xtendFile = loadXtendFile(metamodel);
    if (xtendFile != null) {
        ExecutionContext ctx = getExecutionContext(metamodel);
        ctx = ctx.cloneWithResource(xtendFile);
        ResourceLoader currentThreadResourceLoader = null;
        try {
            currentThreadResourceLoader = getCurrentThreadResourceLoader();
            setCurrentThreadResourceLoader(getResourceLoader(metamodel));
            final Object[] params = new Object[] { metamodel };
            Extension extension = ctx.getExtension("process",params);
            if (extension != null) {
                extension.evaluate(params,ctx);
            }
        }
        catch (EvaluationException e) {
            logger.error("Error encountered processing metamodel " + metamodel.getName() + " with "
                    + xtendFile.getFullyQualifiedname(),e);
        }
        finally {
            setCurrentThreadResourceLoader(currentThreadResourceLoader);
        }
    }
}
项目:xtext-core    文件Xtext2EcoreTransformer.java   
public List<EPackage> getGeneratedPackages() {
    final List<EPackage> result = new ArrayList<EPackage>();
    final ResourceSet resourceSet = grammar.eResource().getResourceSet();
    if (resourceSet == null)
        throw new NullPointerException("resourceSet may not be null");
    Iterables.addAll(result,Iterables.filter(Iterables.transform(
            Iterables.filter(grammar.getmetamodelDeclarations(),Generatedmetamodel.class),new Function<AbstractmetamodelDeclaration,EPackage>() {
                @Override
                public EPackage apply(AbstractmetamodelDeclaration param) {
                    EPackage pack = (EPackage) param.eGet(XtextPackage.Literals.ABSTRACT_metamodel_DECLaraTION__EPACKAGE,false);
                    if (pack != null && !pack.eIsProxy()) {
                        return pack;
                    }
                    return null;
                }
            }),Predicates.notNull()));
    return getPackagesSortedByName(result);
}
项目:xtext-core    文件Xtext2EcoreTransformer.java   
private TypeRef getorComputeReturnType(AbstractRule rule) {
    TypeRef result = rule.getType();
    if (result == null) {
        EClassifier classifier = getClassifierFor(rule);
        if (classifier == null) {
            if (rule.getName() == null)
                return null;
            result = getTypeRef(rule.getName());
        } else
            result = getTypeRef(classifier);
        if (result.getmetamodel() == null) {
            AbstractmetamodelDeclaration bestMatch = null;
            for (AbstractmetamodelDeclaration decl : grammar.getmetamodelDeclarations()) {
                if (decl instanceof Generatedmetamodel && Strings.isEmpty(decl.getAlias())) {
                    bestMatch = decl;
                    break;
                }
            }
            if (result.getmetamodel() == null)
                result.setmetamodel(bestMatch);
        }
        rule.setType(result);
    }
    return result;
}
项目:xtext-core    文件XtextLinker.java   
void discardGeneratedPackages(EObject root) {
    if (root instanceof Grammar) {
        // unload generated metamodels as they will be recreated during linking 
        for (AbstractmetamodelDeclaration metamodelDeclaration : ((Grammar) root).getmetamodelDeclarations()) {
            if (metamodelDeclaration instanceof Generatedmetamodel) {
                EPackage ePackage = (EPackage) metamodelDeclaration.eGet(XtextPackage.Literals.ABSTRACT_metamodel_DECLaraTION__EPACKAGE,false);
                if (ePackage != null && !ePackage.eIsProxy()) {
                    Resource resource = ePackage.eResource();
                    if (resource != null && resource.getResourceSet() != null) {
                        if (unloader != null) {
                            for (EObject content : resource.getContents()) {
                                unloader.unloadRoot(content);
                            }
                        }
                        resource.getResourceSet().getResources().remove(resource);
                    }
                }
            }
        }
    }
}
项目:xtext-core    文件XtextValidator.java   
private void doPropagateValidationResult(Diagnostic diagnostic,Generatedmetamodel metamodel,ValidationMessageAcceptor acceptor) {
    boolean foundEObject = false;
    Object firstData = null;
    for(Object data: diagnostic.getData()) {
        if (firstData == null) {
            firstData = diagnostic.getData().get(0);
        }
        if (data instanceof EObject) {
            if (createMessageForSource(diagnostic,(EObject) data,acceptor)) {
                foundEObject = true;
            } 
            if (data instanceof EStructuralFeature && ((EStructuralFeature) data).getEContainingClass() != firstData) {
                EClass containingClass = ((EStructuralFeature) data).getEContainingClass();
                createMessageForSource(diagnostic,containingClass,acceptor);
            }
        }
    }
    if (!foundEObject) {
        doCreateMessage(
                diagnostic,metamodel,XtextPackage.Literals.ABSTRACT_metamodel_DECLaraTION__EPACKAGE,acceptor);
    }
}
项目:xtext-core    文件XtextValidator.java   
@Check
public void checkReferencedmetamodel(Referencedmetamodel metamodel) throws ValueConverterException {
    if (metamodel.getEPackage() == null)
        return;
    String nsURI = metamodel.getEPackage().getNsURI();
    List<Generatedmetamodel> allGeneratedmetamodels = getInheritedGeneratedmetamodels(metamodel);
    String text = getUsedUri(metamodel);
    for (Generatedmetamodel generatedmetamodel : allGeneratedmetamodels) {
        EPackage generatedPackage = generatedmetamodel.getEPackage();
        if (generatedPackage != null && nsURI.equals((generatedPackage.getNsURI()))) {
            if (!text.equals(nsURI)) {
                addissue("metamodels that have been generated by a super grammar must be referenced by nsURI: " + nsURI,INVALID_PACKAGE_REFERENCE_INHERITED,nsURI);
                return;
            }
            return;
        }
    }
    checkExternalPackage(metamodel,text);
}
项目:xtext-core    文件XtextValidator.java   
@Check
public void checkGeneratedEnumIsValid(EnumLiteralDeclaration decl) {
    EnumRule rule = GrammarUtil.containingEnumRule(decl);
    if (!(rule.getType().getmetamodel() instanceof Generatedmetamodel))
        return;
    if (!(rule.getType().getClassifier() instanceof EEnum))
        return;
    EEnum eEnum = (EEnum) rule.getType().getClassifier();
    List<EnumLiteralDeclaration> declarations = EcoreUtil2.getAllContentsOfType(rule,EnumLiteralDeclaration.class);
    if (declarations.size() == eEnum.getELiterals().size())
        return;
    for (EnumLiteralDeclaration otherDecl : declarations) {
        if (decl == otherDecl) {
            return;
        }
        if (otherDecl.getEnumLiteral() == decl.getEnumLiteral()) {
            if (!decl.getEnumLiteral().getLiteral().equals(decl.getLiteral().getValue()))
                addissue("Enum literal '" + decl.getEnumLiteral().getName()
                        + "' has already been defined with literal '" + decl.getEnumLiteral().getLiteral() + "'.",decl,XtextPackage.Literals.ENUM_LIteraL_DECLaraTION__ENUM_LIteraL,DUPLICATE_ENUM_LIteraL);
            return;
        }
    }
}
项目:xtext-core    文件XtextLinkingService.java   
private List<EObject> createPackage(Generatedmetamodel generatedmetamodel,ILeafNode text) {
    final String nsURI = getmetamodelNsURI(text);
    final URI uri = URI.createURI(nsURI);
    if (uri == null || isReferencedByUsedGrammar(generatedmetamodel,nsURI))
        return Collections.emptyList();
    EPackage pack = ((GeneratedmetamodelImpl)generatedmetamodel).basicGetEPackage();
    if (pack != null && !pack.eIsProxy())
        return singletonList((EObject)pack);
    final EPackage generatedEPackage = EcoreFactory.eINSTANCE.createEPackage();
    generatedEPackage.setName(generatedmetamodel.getName());
    generatedEPackage.setnsprefix(generatedmetamodel.getName());
    generatedEPackage.setNsURI(nsURI);
    final Resource generatedPackageResource = new EcoreResourceFactoryImpl().createResource(uri);
    XtextResourceSet resourceSet = (XtextResourceSet) generatedmetamodel.eResource().getResourceSet();
    if (!resourceSet.getURIResourceMap().containsKey(generatedPackageResource.getURI())) {
        generatedmetamodel.eResource().getResourceSet().getResources().add(generatedPackageResource);
    } else {
        generatedPackageResource.setURI(URI.createURI(nsURI+"_"+generatedmetamodel.hashCode()));
        generatedmetamodel.eResource().getResourceSet().getResources().add(generatedPackageResource);
    }
    generatedPackageResource.getContents().add(generatedEPackage);
    return Collections.<EObject>singletonList(generatedEPackage);
}
项目:xtext-core    文件XtextValidationTest.java   
@Test public void testCycleInTypeHierarchy() throws Exception {
    String grammarasText = "grammar test with org.eclipse.xtext.common.Terminals" +
            " generate test 'http://test'";
    grammarasText += " RuleA: RuleB;";
    grammarasText += " RuleB: RuleC;";
    grammarasText += " RuleC: RuleA;";
    grammarasText += " RuleD: RuleA;";

    Grammar grammar = (Grammar) getModel(grammarasText);
    AbstractmetamodelDeclaration metamodelDeclaration = grammar.getmetamodelDeclarations().get(0);

    XtextValidator validator = get(XtextValidator.class);
    ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(grammar.getRules().get(0).getType(),true,false);
    messageAcceptor.expectedContext(
            grammar.getRules().get(1).getType(),grammar.getRules().get(2).getType()
    );
    validator.setMessageAcceptor(messageAcceptor);
    validator.checkGeneratedPackage((Generatedmetamodel) metamodelDeclaration,Diagnostician.INSTANCE,Collections.EMPTY_MAP);
    messageAcceptor.validate();
}
项目:xtext-core    文件XtextValidationTest.java   
@Test public void testNameClash_01() throws Exception {
    String grammarasText =
            "grammar test with org.eclipse.xtext.common.Terminals\n" +
            "generate test 'http://test'\n" +
            "PRINTF: vars=PRINTF_Vars;\n" +
            "PRINTF_Vars: arg1=ID;";

    Grammar grammar = (Grammar) getModel(grammarasText);
    AbstractmetamodelDeclaration metamodelDeclaration = grammar.getmetamodelDeclarations().get(0);

    XtextValidator validator = get(XtextValidator.class);
    ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(null,false);
    messageAcceptor.expectedContext(
            grammar.getRules().get(0).getAlternatives(),grammar.getRules().get(1).getType()
    );
    validator.setMessageAcceptor(messageAcceptor);
    validator.checkGeneratedPackageForNameClashes((Generatedmetamodel) metamodelDeclaration);
    messageAcceptor.validate();
}
项目:xtext-core    文件XtextValidationTest.java   
@Test public void testNameClash_02() throws Exception {
    String grammarasText =
            "grammar test with org.eclipse.xtext.common.Terminals\n" +
            "generate test 'http://test'\n" +
            "Class returns Class: {Class_} name=ID;\n";

    Grammar grammar = (Grammar) getModel(grammarasText);
    AbstractmetamodelDeclaration metamodelDeclaration = grammar.getmetamodelDeclarations().get(0);

    XtextValidator validator = get(XtextValidator.class);
    ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(null,false);
    CompoundElement element = (CompoundElement) grammar.getRules().get(0).getAlternatives();
    messageAcceptor.expectedContext(
            grammar.getRules().get(0).getType(),((Action) element.getElements().get(0)).getType()
    );
    validator.setMessageAcceptor(messageAcceptor);
    validator.checkGeneratedPackage((Generatedmetamodel) metamodelDeclaration,Collections.EMPTY_MAP);
    messageAcceptor.validate();
}
项目:xtext-core    文件XtextValidationTest.java   
@Test public void testNameClash_03() throws Exception {
    String grammarasText =
            "grammar test with org.eclipse.xtext.common.Terminals\n" +
            "generate test 'http://test'\n" +
            "Foo: myVars=ID my_vars=ID;\n";

    Grammar grammar = (Grammar) getModel(grammarasText);
    AbstractmetamodelDeclaration metamodelDeclaration = grammar.getmetamodelDeclarations().get(0);

    XtextValidator validator = get(XtextValidator.class);
    ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(null,element.getElements().get(0),element.getElements().get(1)
    );
    validator.setMessageAcceptor(messageAcceptor);
    validator.checkGeneratedPackage((Generatedmetamodel) metamodelDeclaration,Collections.EMPTY_MAP);
    messageAcceptor.validate();
}
项目:xtext-extras    文件JavaValidatorFragment.java   
@Override
protected List<Object> getParameters(Grammar grammar) {
    List<String> packageqnames = new ArrayList<String>();
    List<Generatedmetamodel> list = EcoreUtil2.typeSelect(grammar.getmetamodelDeclarations(),Generatedmetamodel.class);
    for (Generatedmetamodel generatedmetamodel : list) {
        packageqnames.add(getGeneratedEPackageName(grammar,getNaming(),generatedmetamodel.getEPackage()));
    }
    List<Object> parameters = Lists.newArrayList((Object) packageqnames);
    parameters.add(this.composedChecks);
    parameters.add(getValidatorSuperClassName(grammar));
    return parameters;
}
项目:xtext-extras    文件Generator.java   
@Override
protected void checkConfigurationInternal(Issues issues) {
    naming.setProjectNameRt(getProjectNameRt());
    naming.setProjectNameIde(getProjectNameIde());
    naming.setIdeBasePackage(!isIde() && isUi() ? getProjectNameUi() : getProjectNameIde());
    naming.setProjectNameUi(getProjectNameUi());
    naming.setUiBasePackage(getProjectNameUi());
    naming.setActivatorName(getActivator());
    naming.setPathTestProject(getPathTestProject());
    naming.setFileHeader(getFileHeader());
    naming.setClassAnnotations(getClassAnnotationsAsstring());
    naming.setAnnotationImports(getAnnotationImportsAsstring());
    naming.setHasUI(isUi());
    naming.setHasIde(isIde());
    Map<String,Grammar> uris = new HashMap<String,Grammar>();
    for (LanguageConfig config : languageConfigs) {
        config.registerNaming(naming);
        config.checkConfiguration(issues);
        Grammar grammar = config.getGrammar();
        List<Generatedmetamodel> select = EcoreUtil2.typeSelect(grammar.getmetamodelDeclarations(),Generatedmetamodel.class);
        for (Generatedmetamodel generatedmetamodel : select) {
            String nsURI = generatedmetamodel.getEPackage().getNsURI();
            if (uris.containsKey(nsURI)) {
                issues.addError("Duplicate generated grammar with nsURI '" + nsURI + "' in "
                        + uris.get(nsURI).getName() + " and " + grammar.getName());
            } else {
                uris.put(nsURI,grammar);
            }
        }
    }
    if (getProjectNameRt() == null)
        issues.addError("The property 'projectNameRt' is mandatory");
    if (isUiMergedIntoRt() && getPathIdeProject() != null && ! isIdeMergedIntoRt()) {
        issues.addError("Cannot have a dedicated ide project when ui project is merged into runtime project");
    }
}
项目:xtext-extras    文件ValidatorFragment.java   
protected Collection<EPackage> getRegistryPackagesTovalidate() {
  Collection<EPackage> _xblockexpression = null;
  {
    final Collection<EPackage> packages = GrammarUtil.allEPackagesTovalidate(this.grammar);
    final Function1<Generatedmetamodel,EPackage> _function = (Generatedmetamodel it) -> {
      return it.getEPackage();
    };
    packages.removeAll(
      IterableExtensions.<EPackage>toList(IterableExtensions.<Generatedmetamodel,EPackage>map(Iterables.<Generatedmetamodel>filter(GrammarUtil.allmetamodelDeclarations(this.grammar),_function)));
    _xblockexpression = packages;
  }
  return _xblockexpression;
}
项目:xtext-extras    文件Xtext2EcoreTransformerTest.java   
@Override
public void process(final Generatedmetamodel metamodel) {
  boolean _equals = this.testmetamodel.equals(metamodel);
  if (_equals) {
    this.called++;
  }
}
项目:xtext-core    文件XtendXtext2EcorePostProcessor.java   
/**
 * Expects an Xtend file named <code>MyDsl</code>PostProcessor.ext with an extension with signature
 * process(xtext::Generatedmetamodel) in the same folder as the grammar file.
 * 
 * @param metamodel
 *            the metamodel to augment
 * @return the xtendFile to execute
 */
protected Resource loadXtendFile(Generatedmetamodel metamodel) {
    if (xtendFile == null) {
        final String extension = getExtensionName(metamodel);
        try {
            URI uri = getXtendFileLocation(metamodel);
            if (uri != null) {
                URIConverter uriConverter = metamodel.eResource().getResourceSet().getURIConverter();
                if (uriConverter.exists(uri,null)) {
                    InputStream in = uriConverter.createInputStream(uri);
                    try {
                        XtendResourceParser parser = new XtendResourceParser();
                        xtendFile = parser.parse(new InputStreamReader(in),extension + '.'
                                + XtendFile.FILE_EXTENSION);
                        fireXtendFileLoaded();
                    } finally {
                        if (in != null)
                            in.close();
                    }
                }
            }
        } catch (ClasspathUriResolutionException ignored) {
            // no xtend file found
        } catch (Exception e) {
            logger.error("Could not parse " + extension,e);
        }
    }
    return xtendFile;
}
项目:xtext-core    文件XtendXtext2EcorePostProcessor.java   
protected URI getXtendFileLocation(Generatedmetamodel metamodel) {
    URI uri = metamodel.eResource().getURI();
    // check if uri can be used for resolve
    if (!uri.isHierarchical() || uri.isRelative())
        return null;
    uri = URI.createURI(Strings.lastToken(getExtensionName(metamodel),"::")).appendFileExtension(
            XtendFile.FILE_EXTENSION).resolve(uri);
    return uri;
}
项目:xtext-core    文件Xtext2EcoreTransformer.java   
private Set<String> getGeneratedEPackageURIs() {
    List<Generatedmetamodel> list = EcoreUtil2.typeSelect(grammar.getmetamodelDeclarations(),Generatedmetamodel.class);
    return Sets.newLinkedHashSet(Iterables.transform(list,new Function<Generatedmetamodel,String>() {
        @Override
        public String apply(Generatedmetamodel from) {
            return from.getEPackage()!=null?from.getEPackage().getNsURI() : null;
        }
    }));
}
项目:xtext-core    文件Xtext2EcoreTransformer.java   
private void addGeneratedEPackage(Generatedmetamodel generatedmetamodel) throws TransformationException {
    // we do not allow the same alias twice for generated metamodels
    String alias = Strings.emptyIfNull(generatedmetamodel.getAlias());
    if (generatedEPackages.containsKey(alias))
        throw new TransformationException(TransformationErrorCode.AliasFormetamodelAlreadyExists,"alias '" + alias
                + "' already exists",generatedmetamodel);

    if (generatedmetamodel.getEPackage() == null)
        throw new TransformationException(TransformationErrorCode.UnkNownmetamodelAlias,"Cannot create EPackage without NsURI.",generatedmetamodel);

    // instantiate EPackages for generated metamodel
    EPackage generatedEPackage = generatedmetamodel.getEPackage();
    generatedEPackages.put(alias,generatedEPackage);
    collectClassInfosOf(generatedEPackage,generatedmetamodel);
}
项目:xtext-core    文件Xtext2EcoreTransformer.java   
private void postProcessGeneratedPackages() {
    if (postProcessor != null) {
        final Iterable<Generatedmetamodel> generatedmetamodels = Iterables.filter(grammar
                .getmetamodelDeclarations(),Generatedmetamodel.class);
        for (Generatedmetamodel metamodel : generatedmetamodels) {
            postProcessor.process(metamodel);
        }
    }
}
项目:xtext-core    文件XtextValidator.java   
@Check
public void checkGeneratedmetamodel(Generatedmetamodel metamodel) {
    if (metamodel.getName() != null && metamodel.getName().length() != 0)
        if (Character.isUpperCase(metamodel.getName().charat(0)))
            addissue("metamodel names should start with a lower case letter.",XtextPackage.Literals.GENERATED_metamodel__NAME,INVALID_metamodel_NAME,metamodel.getName());
}
项目:xtext-core    文件XtextValidator.java   
@Check
public void checkGeneratedPackage(Generatedmetamodel metamodel) {
    Map<Object,Object> context = getContext();
    if (context != null) {
        Diagnostician diagnostician = (Diagnostician) context.get(EValidator.class);
        if (diagnostician != null)
            checkGeneratedPackage(metamodel,diagnostician,context);
    }
}
项目:xtext-core    文件XtextValidator.java   
@Check
public void checkGeneratedPackageForNameClashes(Generatedmetamodel metamodel) {
    EPackage pack = metamodel.getEPackage();
    Multimap<String,ENamedElement> constantNametoElement = HashMultimap.create();
    Multimap<String,ENamedElement> accessorNametoElement = HashMultimap.create();
    if (pack != null) {
        for(EClassifier classifier: pack.getEClassifiers()) {
            String accessorName = classifier.getName();
            if ("Class".equals(accessorName) || "Name".equals(accessorName))
                accessorName += "_";
            accessorNametoElement.put("get" + accessorName,classifier);
            String classifierConstantName = CodeGenUtil2.format(classifier.getName(),'_',null,true).toupperCase();
            constantNametoElement.put(classifierConstantName,classifier);
            if (classifier instanceof EClass) {
                for(EStructuralFeature feature: ((EClass) classifier).geteallStructuralFeatures()) {
                    String featureConstantPart = CodeGenUtil2.format(feature.getName(),false,false).toupperCase();
                    String featureConstantName = classifierConstantName + "__" + featureConstantPart;
                    constantNametoElement.put(featureConstantName,feature);
                    String featureAccessorName = "get" + classifier.getName() + "_" + Strings.toFirstUpper(feature.getName());
                    accessorNametoElement.put(featureAccessorName,feature);
                }
            }
        }
    }
    createMessageForNameClashes(constantNametoElement);
    createMessageForNameClashes(accessorNametoElement);
}
项目:xtext-core    文件XtextValidator.java   
@Check
public void checkGeneratedPackageNotEmpty(Generatedmetamodel metamodel) {
    EPackage pack = metamodel.getEPackage();
    if (pack != null && pack.getEClassifiers().isEmpty()) {
        getMessageAcceptor().acceptError(
                "Generated package '" + metamodel.getName() + "' may not be empty.",ValidationMessageAcceptor.INSIGNIFICANT_INDEX,EMPTY_GENERATED_PACKAGE);
    }
}
项目:xtext-core    文件XtextValidator.java   
private void propageValidationResult(Diagnostic diagnostic,ValidationMessageAcceptor acceptor) {
    if (diagnostic.getSeverity() != Diagnostic.OK) {
        if (diagnostic.getCode() != 0) {
            List<?> data = diagnostic.getData();
            if (!data.isEmpty() && data.get(0) instanceof EObject) {
                doPropagateValidationResult(diagnostic,acceptor);
            }
        }
        for(Diagnostic child: diagnostic.getChildren())
            propageValidationResult(child,acceptor);
    }
}
项目:xtext-core    文件XtextValidator.java   
protected List<Generatedmetamodel> getInheritedGeneratedmetamodels(Referencedmetamodel metamodel) {
    List<Generatedmetamodel> allGeneratedmetamodels = new ArrayList<Generatedmetamodel>();
    Grammar grammar = GrammarUtil.getGrammar(metamodel);
    Set<Grammar> visited = Sets.newHashSet();
    for (Grammar usedGrammar : grammar.getUsedGrammars())
        Iterables.addAll(allGeneratedmetamodels,getAllGeneratedmetamodels(usedGrammar,visited));
    if (allGeneratedmetamodels.isEmpty())
        return Collections.emptyList();
    return allGeneratedmetamodels;
}
项目:xtext-core    文件XtextValidator.java   
private Iterable<Generatedmetamodel> getAllGeneratedmetamodels(Grammar grammar,Set<Grammar> visited) {
    Iterable<Generatedmetamodel> result = Iterables.filter(grammar.getmetamodelDeclarations(),Generatedmetamodel.class);
    for (Grammar gr : grammar.getUsedGrammars()) {
        if (visited.add(gr))
            result = Iterables.concat(result,getAllGeneratedmetamodels(gr,visited));
    }
    return result;
}
项目:xtext-core    文件XtextLocationInFileProvider.java   
@Override
protected EStructuralFeature getIdentifierFeature(EObject obj) {
    if (obj instanceof AbstractmetamodelDeclaration) {
        AbstractmetamodelDeclaration decl = (AbstractmetamodelDeclaration) obj;
        if (decl.getAlias() != null)
            return XtextPackage.Literals.ABSTRACT_metamodel_DECLaraTION__ALIAS;
        if (decl instanceof Generatedmetamodel && ((Generatedmetamodel) decl).getName() != null)
            return XtextPackage.Literals.GENERATED_metamodel__NAME;
        return XtextPackage.Literals.ABSTRACT_metamodel_DECLaraTION__EPACKAGE;
    }
    return super.getIdentifierFeature(obj);
}
项目:xtext-core    文件XtextLinkingService.java   
@Override
public List<EObject> getLinkedobjects(EObject context,EReference ref,INode node) throws IllegalNodeException {
    if (ref == XtextPackage.eINSTANCE.getGrammar_UsedGrammars())
        return getUsedGrammar((Grammar) context,node);
    if (ref == XtextPackage.eINSTANCE.getTypeRef_metamodel())
        return getLinkedmetamodel((TypeRef)context,ref,(ILeafNode) node);
    if (ref == XtextPackage.eINSTANCE.getAbstractmetamodelDeclaration_EPackage() && context instanceof Generatedmetamodel)
        return createPackage((Generatedmetamodel) context,(ILeafNode) node);
    if (ref == XtextPackage.eINSTANCE.getAbstractmetamodelDeclaration_EPackage() && context instanceof Referencedmetamodel)
        return getPackage((Referencedmetamodel)context,(ILeafNode) node);
    return super.getLinkedobjects(context,node);
}
项目:xtext-core    文件XtextLinkingService.java   
private boolean isReferencedByUsedGrammar(Generatedmetamodel generatedmetamodel,String nsURI) {
    final Grammar grammar = GrammarUtil.getGrammar(generatedmetamodel);
    if (grammar != null) {
        final Set<Grammar> visitedGrammars = Sets.newHashSet(grammar);
        for (Grammar usedGrammar: grammar.getUsedGrammars()) {
            if (isReferencedByUsedGrammar(usedGrammar,nsURI,visitedGrammars))
                return true;
        }
    }
    return false;
}
项目:xtext-core    文件ValidatorFragment2.java   
protected Collection<EPackage> getRegistryPackagesTovalidate() {
  final Collection<EPackage> packages = GrammarUtil.allEPackagesTovalidate(this.getGrammar());
  final Function1<Generatedmetamodel,EPackage> _function = (Generatedmetamodel it) -> {
    return it.getEPackage();
  };
  packages.removeAll(IterableExtensions.<EPackage>toList(IterableExtensions.<Generatedmetamodel,EPackage>map(Iterables.<Generatedmetamodel>filter(GrammarUtil.allmetamodelDeclarations(this.getGrammar()),_function)));
  return packages;
}
项目:xtext-core    文件XtextGenerator.java   
@Override
protected void checkConfigurationInternal(final Issues issues) {
  this.initialize();
  final MweIssues generatorIssues = new MweIssues(this,issues);
  this.configuration.checkConfiguration(generatorIssues);
  final HashMap<String,Grammar>();
  for (final XtextGeneratorLanguage language : this.languageConfigs) {
    {
      language.checkConfiguration(generatorIssues);
      Iterable<Generatedmetamodel> _filter = Iterables.<Generatedmetamodel>filter(language.getGrammar().getmetamodelDeclarations(),Generatedmetamodel.class);
      for (final Generatedmetamodel generatedmetamodel : _filter) {
        {
          final String nsURI = generatedmetamodel.getEPackage().getNsURI();
          boolean _containsKey = uris.containsKey(nsURI);
          if (_containsKey) {
            String _name = uris.get(nsURI).getName();
            String _plus = ((("Duplicate generated grammar with nsURI \'" + nsURI) + "\' in ") + _name);
            String _plus_1 = (_plus + " and ");
            String _name_1 = language.getGrammar().getName();
            String _plus_2 = (_plus_1 + _name_1);
            generatorIssues.addError(_plus_2);
          } else {
            uris.put(nsURI,language.getGrammar());
          }
        }
      }
    }
  }
}
项目:xtext-core    文件XtextValidationTest.java   
@Test public void testDuplicateFeatures_01() throws Exception {
    String grammarasText =
            "grammar test with org.eclipse.xtext.common.Terminals\n" +
            "generate test 'http://test'\n" +
            "Model: Parent1 | Parent2 | noparent;\n" + 
            "noparent: foo=ID;" +
            "Parent1: Sub1 | Sub2;\n" + 
            "Parent2: Sub2 | Sub3;\n" + 
            "Sub1: x=ID;\n" + 
            "Sub2: x=ID;\n" + 
            "Sub3: x=ID;\n";

    Grammar grammar = (Grammar) getModel(grammarasText);
    AbstractmetamodelDeclaration metamodelDeclaration = grammar.getmetamodelDeclarations().get(0);

    XtextValidator validator = get(XtextValidator.class);
    ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(null,false);
    messageAcceptor.expectedContext(
            grammar.getRules().get(2).getType(),grammar.getRules().get(3).getType(),grammar.getRules().get(5).getType(),grammar.getRules().get(4).getAlternatives(),grammar.getRules().get(5).getAlternatives(),grammar.getRules().get(6).getAlternatives()
    );
    validator.setMessageAcceptor(messageAcceptor);
    validator.checkGeneratedPackage((Generatedmetamodel) metamodelDeclaration,Collections.EMPTY_MAP);
    messageAcceptor.validate();
}
项目:xtext-core    文件XtextValidationTest.java   
@Test public void testDuplicateFeatures_02() throws Exception {
    String grammarasText =
            "grammar test with org.eclipse.xtext.common.Terminals\n" +
            "generate test 'http://test'\n" +
            "A : (b+=B)*;\n" + 
            "B : C | D;\n" +
            "C : 'c' name=ID ('e' e+=E)+;\n" + 
            "E : name=ID;\n" + 
            "F : C | E;\n" + 
            "D : 'd' name=ID 'ref' ref=[F];";

    Grammar grammar = (Grammar) getModel(grammarasText);
    AbstractmetamodelDeclaration metamodelDeclaration = grammar.getmetamodelDeclarations().get(0);

    XtextValidator validator = get(XtextValidator.class);
    ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(null,grammar.getRules().get(2).getType(),grammar.getRules().get(4).getType(),((CompoundElement) grammar.getRules().get(2).getAlternatives()).getElements().get(1),grammar.getRules().get(3).getAlternatives(),((CompoundElement) grammar.getRules().get(5).getAlternatives()).getElements().get(1)
    );
    validator.setMessageAcceptor(messageAcceptor);
    validator.checkGeneratedPackage((Generatedmetamodel) metamodelDeclaration,Collections.EMPTY_MAP);
    messageAcceptor.validate();
}
项目:xtext-core    文件XtextValidationTest.java   
@Test public void testGeneratedPackageNotEmpty() throws Exception {
    String grammarasText =
            "grammar test with org.eclipse.xtext.common.Terminals\n" +
            "generate test 'http://test'\n" +
            "Foo: 'a';\n";

    Grammar grammar = (Grammar) getModel(grammarasText);
    AbstractmetamodelDeclaration metamodelDeclaration = grammar.getmetamodelDeclarations().get(0);

    XtextValidator validator = get(XtextValidator.class);
    ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(metamodelDeclaration,false);
    validator.setMessageAcceptor(messageAcceptor);
    validator.checkGeneratedPackageNotEmpty((Generatedmetamodel) metamodelDeclaration);
    messageAcceptor.validate();
}
项目:xtext-core    文件ToEcoreTrafoTest.java   
@Test public void testConcreteLanguagetometamodel1() throws Exception {
    XtextResource r = getResource("classpath:/" + ConcreteTestLanguage.class.getName().replace('.','/') + ".xtext");
    EObject element = r.getContents().get(0);
    Grammar g = (Grammar) element;
    List<AbstractmetamodelDeclaration> mms = Lists.<AbstractmetamodelDeclaration>newArrayList(
            Iterables.filter(g.getmetamodelDeclarations(),Generatedmetamodel.class));
    assertNotNull(mms);
    assertEquals(1,mms.size());
}
项目:xtext-core    文件Xtext2EcoreTransformerTest.java   
@Override
public void process(final Generatedmetamodel metamodel) {
  boolean _equals = this.testmetamodel.equals(metamodel);
  if (_equals) {
    this.called++;
  }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。