Java Code Examples for org.eclipse.xtext.GeneratedMetamodel#getEPackage()

The following examples show how to use org.eclipse.xtext.GeneratedMetamodel#getEPackage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XtextValidator.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@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,
						metamodel,
						XtextPackage.Literals.ABSTRACT_METAMODEL_DECLARATION__EPACKAGE,
						INVALID_PACKAGE_REFERENCE_INHERITED,
						nsURI);
				return;
			}
			return;
		}
	}
	checkExternalPackage(metamodel, text);
}
 
Example 2
Source File: ValidatorFragment.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
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), GeneratedMetamodel.class), _function)));
    _xblockexpression = packages;
  }
  return _xblockexpression;
}
 
Example 3
Source File: Xtext2EcoreTransformer.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
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);
}
 
Example 4
Source File: XtextValidator.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@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, true).toUpperCase();
			constantNameToElement.put(classifierConstantName, classifier);
			if (classifier instanceof EClass) {
				for(EStructuralFeature feature: ((EClass) classifier).getEAllStructuralFeatures()) {
					String featureConstantPart = CodeGenUtil2.format(feature.getName(), '_', null, 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);
}
 
Example 5
Source File: XtextValidator.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@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.",
				metamodel, 
				XtextPackage.Literals.ABSTRACT_METAMODEL_DECLARATION__EPACKAGE,
				ValidationMessageAcceptor.INSIGNIFICANT_INDEX,
				EMPTY_GENERATED_PACKAGE);
	}
}
 
Example 6
Source File: ValidatorFragment2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
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()), GeneratedMetamodel.class), _function)));
  return packages;
}
 
Example 7
Source File: ValidatorFragment.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public Iterable<EPackage> getGeneratedPackagesToValidate() {
  final Function1<GeneratedMetamodel, EPackage> _function = (GeneratedMetamodel it) -> {
    return it.getEPackage();
  };
  return IterableExtensions.<GeneratedMetamodel, EPackage>map(Iterables.<GeneratedMetamodel>filter(this.grammar.getMetamodelDeclarations(), GeneratedMetamodel.class), _function);
}
 
Example 8
Source File: ValidatorFragment2.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected Iterable<EPackage> getGeneratedPackagesToValidate() {
  final Function1<GeneratedMetamodel, EPackage> _function = (GeneratedMetamodel it) -> {
    return it.getEPackage();
  };
  return IterableExtensions.<GeneratedMetamodel, EPackage>map(Iterables.<GeneratedMetamodel>filter(this.getGrammar().getMetamodelDeclarations(), GeneratedMetamodel.class), _function);
}