org.eclipse.xtext.xtext.generator.util.GenModelUtil2 Java Examples
The following examples show how to use
org.eclipse.xtext.xtext.generator.util.GenModelUtil2.
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: EMFGeneratorFragment.java From xtext-extras with Eclipse Public License 2.0 | 6 votes |
/** * @since 2.11 */ @Override public Set<Binding> getGuiceBindingsRt(Grammar grammar) { if (isBindEPackageAndEFactory()) { BindFactory bindFactory = new BindFactory(); // Register generated EPackage and EFactory instances in the runtime module for (EPackage pkg: getGeneratedEPackages(grammar)) { GenPackage genPkg = GenModelUtil2.getGenPackage(pkg, grammar.eResource().getResourceSet()); bindFactory .addTypeToInstance(genPkg.getQualifiedPackageInterfaceName(), genPkg.getQualifiedPackageInterfaceName()+".eINSTANCE") .addTypeToInstance(genPkg.getQualifiedFactoryInterfaceName(), genPkg.getQualifiedFactoryInterfaceName()+".eINSTANCE"); } return bindFactory.getBindings(); } else { return Collections.emptySet(); } }
Example #2
Source File: TypeReference.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
private static TypeReference.QualifiedClassName getQualifiedName(final EPackage epackage, final ResourceSet resourceSet) { TypeReference.QualifiedClassName _xblockexpression = null; { final GenPackage genPackage = GenModelUtil2.getGenPackage(epackage, resourceSet); String _xifexpression = null; boolean _isSuppressEMFMetaData = genPackage.getGenModel().isSuppressEMFMetaData(); if (_isSuppressEMFMetaData) { _xifexpression = genPackage.getQualifiedPackageClassName(); } else { _xifexpression = genPackage.getReflectionPackageName(); } final String packageName = _xifexpression; String _packageInterfaceName = genPackage.getPackageInterfaceName(); _xblockexpression = new TypeReference.QualifiedClassName(packageName, _packageInterfaceName); } return _xblockexpression; }
Example #3
Source File: EMFGeneratorFragment2.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
private Map<String, EPackage> findEPackagesInGenPackages(final Collection<String> packageNsURIs, final ResourceSet resourceSet) { final HashMap<String, EPackage> result = CollectionLiterals.<String, EPackage>newHashMap(); for (final String nsURI : packageNsURIs) { { final Resource resource = GenModelUtil2.getGenModelResource(null, nsURI, resourceSet); if ((resource != null)) { final GenModel loadedGenModel = IterableExtensions.<GenModel>head(Iterables.<GenModel>filter(resource.getContents(), GenModel.class)); if ((loadedGenModel != null)) { final GenPackage genPackage = this.findGenPackageByNsURI(loadedGenModel, nsURI); result.put(nsURI, genPackage.getEcorePackage()); } } } } return result; }
Example #4
Source File: EMFGeneratorFragment2.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
protected List<GenPackage> getGenPackagesForPackages(final GenModel existingGenModel, final Collection<EPackage> packs) { final ArrayList<GenPackage> result = CollectionLiterals.<GenPackage>newArrayList(); for (final EPackage pkg : packs) { final Function1<GenPackage, Boolean> _function = (GenPackage it) -> { EPackage _ecorePackage = it.getEcorePackage(); String _nsURI = null; if (_ecorePackage!=null) { _nsURI=_ecorePackage.getNsURI(); } String _nsURI_1 = pkg.getNsURI(); return Boolean.valueOf(Objects.equal(_nsURI, _nsURI_1)); }; boolean _exists = IterableExtensions.<GenPackage>exists(existingGenModel.getGenPackages(), _function); boolean _not = (!_exists); if (_not) { result.add(GenModelUtil2.getGenPackage(pkg, existingGenModel.eResource().getResourceSet())); } } final Comparator<GenPackage> _function_1 = (GenPackage o1, GenPackage o2) -> { return EcoreUtil.getURI(o1).toString().compareTo(EcoreUtil.getURI(o2).toString()); }; Collections.<GenPackage>sort(result, _function_1); return result; }
Example #5
Source File: AbstractCodeElementExtractor.java From sarl with Apache License 2.0 | 5 votes |
@Override public TypeReference newTypeReference(EClassifier classifier) { if (classifier == null) { return new TypeReference(Object.class); } final String name = GenModelUtil2.getJavaTypeName(classifier, classifier.eResource().getResourceSet()); if (Strings.isEmpty(name)) { return new TypeReference(Object.class); } return new TypeReference(name); }
Example #6
Source File: SerializerFragment2.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
private StringConcatenationClient genMethodCreateSequence() { StringConcatenationClient _xblockexpression = null; { final Function1<IGrammarConstraintProvider.IConstraint, Pair<IGrammarConstraintProvider.IConstraint, IGrammarConstraintProvider.IConstraint>> _function = (IGrammarConstraintProvider.IConstraint it) -> { return Pair.<IGrammarConstraintProvider.IConstraint, IGrammarConstraintProvider.IConstraint>of(it, it); }; final Map<IGrammarConstraintProvider.IConstraint, IGrammarConstraintProvider.IConstraint> superConstraints = SerializerFragment2.<IGrammarConstraintProvider.IConstraint, IGrammarConstraintProvider.IConstraint>toMap(IterableExtensions.<IGrammarConstraintProvider.IConstraint, Pair<IGrammarConstraintProvider.IConstraint, IGrammarConstraintProvider.IConstraint>>map(this._semanticSequencerExtensions.getGrammarConstraints(this._semanticSequencerExtensions.getSuperGrammar(this.getGrammar())), _function)); StringConcatenationClient _client = new StringConcatenationClient() { @Override protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) { _builder.append("@Override"); _builder.newLine(); _builder.append("public void sequence("); _builder.append(ISerializationContext.class); _builder.append(" context, "); _builder.append(EObject.class); _builder.append(" semanticObject) {"); _builder.newLineIfNotEmpty(); _builder.append("\t"); _builder.append(EPackage.class, "\t"); _builder.append(" epackage = semanticObject.eClass().getEPackage();"); _builder.newLineIfNotEmpty(); _builder.append("\t"); _builder.append(ParserRule.class, "\t"); _builder.append(" rule = context.getParserRule();"); _builder.newLineIfNotEmpty(); _builder.append("\t"); _builder.append(Action.class, "\t"); _builder.append(" action = context.getAssignedAction();"); _builder.newLineIfNotEmpty(); _builder.append("\t"); _builder.append(Set.class, "\t"); _builder.append("<"); _builder.append(Parameter.class, "\t"); _builder.append("> parameters = context.getEnabledBooleanParameters();"); _builder.newLineIfNotEmpty(); { Iterable<Pair<Integer, EPackage>> _indexed = IterableExtensions.<EPackage>indexed(SerializerFragment2.this.getAccessedPackages()); for(final Pair<Integer, EPackage> pkg : _indexed) { _builder.append("\t"); { Integer _key = pkg.getKey(); boolean _greaterThan = ((_key).intValue() > 0); if (_greaterThan) { _builder.append("else "); } } _builder.append("if (epackage == "); EPackage _value = pkg.getValue(); _builder.append(_value, "\t"); _builder.append("."); String _packageLiteral = GenModelUtil2.getPackageLiteral(); _builder.append(_packageLiteral, "\t"); _builder.append(")"); _builder.newLineIfNotEmpty(); _builder.append("\t"); _builder.append("\t"); _builder.append("switch (semanticObject.eClass().getClassifierID()) {"); _builder.newLine(); { Iterable<EClass> _accessedClasses = SerializerFragment2.this.getAccessedClasses(pkg.getValue()); for(final EClass type : _accessedClasses) { _builder.append("\t"); _builder.append("\t"); _builder.append("case "); EPackage _value_1 = pkg.getValue(); _builder.append(_value_1, "\t\t"); _builder.append("."); String _intLiteral = GenModelUtil2.getIntLiteral(type, SerializerFragment2.this.getLanguage().getResourceSet()); _builder.append(_intLiteral, "\t\t"); _builder.append(":"); _builder.newLineIfNotEmpty(); _builder.append("\t"); _builder.append("\t"); _builder.append("\t"); StringConcatenationClient _genMethodCreateSequenceCaseBody = SerializerFragment2.this.genMethodCreateSequenceCaseBody(superConstraints, type); _builder.append(_genMethodCreateSequenceCaseBody, "\t\t\t"); _builder.newLineIfNotEmpty(); } } _builder.append("\t"); _builder.append("\t"); _builder.append("}"); _builder.newLine(); } } _builder.append("\t"); _builder.append("if (errorAcceptor != null)"); _builder.newLine(); _builder.append("\t\t"); _builder.append("errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));"); _builder.newLine(); _builder.append("}"); _builder.newLine(); } }; _xblockexpression = _client; } return _xblockexpression; }
Example #7
Source File: Formatter2Fragment2.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
protected String getGetAccessor(final EStructuralFeature feature) { return GenModelUtil2.getGenFeature(feature, this.getLanguage().getResourceSet()).getName(); }