Java Code Examples for org.eclipse.emf.ecore.EPackage#getNsURI()

The following examples show how to use org.eclipse.emf.ecore.EPackage#getNsURI() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
public static GenPackage getGenPackage(EPackage pkg, ResourceSet resourceSet) {
	String nsURI = pkg.getNsURI();
	String location = null;
	if (pkg.eResource() != null && pkg.eResource().getURI() != null)
		location = pkg.eResource().getURI().toString();
	Resource genModelResource = getGenModelResource(location, nsURI, resourceSet);
	if (genModelResource != null) {
		for (EObject model : genModelResource.getContents()) {
			if (model instanceof GenModel) {
				GenPackage genPkg = ((GenModel) model).findGenPackage(pkg);
				if (genPkg != null) {
					genPkg.getEcorePackage().getEClassifiers();
					return genPkg;
				}
			}
		}
		throw new RuntimeException("No GenPackage for NsURI " + nsURI + " found in " + genModelResource.getURI());
	}
	throw new RuntimeException("No GenPackage for NsURI " + nsURI + ".");
}
 
Example 2
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 3
@Override
protected String getDisplayString(EObject element, String proposal, String shortName) {
	if (element instanceof AbstractMetamodelDeclaration) {
		AbstractMetamodelDeclaration decl = (AbstractMetamodelDeclaration) element;
		if (!Strings.isEmpty(decl.getAlias()))
			return decl.getAlias();
	} else if (element instanceof EPackage) {
		EPackage pack = (EPackage) element;
		return pack.getName() + " - " + pack.getNsURI();
	}
	return super.getDisplayString(element, proposal, shortName);
}
 
Example 4
public static GenPackage getGenPackage(final EPackage pkg, final ResourceSet resourceSet) {
  final String nsURI = pkg.getNsURI();
  String location = null;
  Resource _eResource = pkg.eResource();
  URI _uRI = null;
  if (_eResource!=null) {
    _uRI=_eResource.getURI();
  }
  boolean _tripleNotEquals = (_uRI != null);
  if (_tripleNotEquals) {
    location = pkg.eResource().getURI().toString();
  }
  final Resource genModelResource = GenModelUtil2.getGenModelResource(location, nsURI, resourceSet);
  if ((genModelResource != null)) {
    EList<EObject> _contents = genModelResource.getContents();
    for (final EObject model : _contents) {
      if ((model instanceof GenModel)) {
        final GenPackage genPkg = ((GenModel)model).findGenPackage(pkg);
        if ((genPkg != null)) {
          genPkg.getEcorePackage().getEClassifiers();
          return genPkg;
        }
      }
    }
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("No GenPackage for NsURI ");
    _builder.append(nsURI);
    _builder.append(" found in ");
    URI _uRI_1 = genModelResource.getURI();
    _builder.append(_uRI_1);
    throw new RuntimeException(_builder.toString());
  }
  StringConcatenation _builder_1 = new StringConcatenation();
  _builder_1.append("No GenPackage for NsURI ");
  _builder_1.append(nsURI);
  _builder_1.append(".");
  throw new RuntimeException(_builder_1.toString());
}
 
Example 5
public static boolean isEcoreType(final EClassifier it) {
  EPackage _ePackage = it.getEPackage();
  String _nsURI = null;
  if (_ePackage!=null) {
    _nsURI=_ePackage.getNsURI();
  }
  return Objects.equal(_nsURI, "http://www.eclipse.org/emf/2002/Ecore");
}
 
Example 6
@Override
protected String name(EPackage ePackage) {
	return ePackage.getNsURI();
}
 
Example 7
protected void addAllGrammarsToResource(final Resource resource, final Grammar grammar, final Set<Grammar> visitedGrammars) {
  boolean _add = visitedGrammars.add(grammar);
  boolean _not = (!_add);
  if (_not) {
    return;
  }
  resource.getContents().add(grammar);
  EList<AbstractMetamodelDeclaration> _metamodelDeclarations = grammar.getMetamodelDeclarations();
  for (final AbstractMetamodelDeclaration metamodelDecl : _metamodelDeclarations) {
    {
      final EPackage pack = metamodelDecl.getEPackage();
      final Resource packResource = pack.eResource();
      String _string = packResource.getURI().toString();
      String _nsURI = pack.getNsURI();
      boolean _notEquals = (!Objects.equal(_string, _nsURI));
      if (_notEquals) {
        final ResourceSet packResourceSet = packResource.getResourceSet();
        if ((packResourceSet != null)) {
          EPackage topMost = pack;
          while (((topMost.getESuperPackage() != null) && (topMost.getESuperPackage().eResource() == topMost.eResource()))) {
            topMost = topMost.getESuperPackage();
          }
          if ((packResource.getContents().contains(topMost) && (packResource.getContents().size() == 1))) {
            boolean _isEmpty = topMost.getEClassifiers().isEmpty();
            boolean _not_1 = (!_isEmpty);
            if (_not_1) {
              packResource.setURI(URI.createURI(topMost.getNsURI()));
            } else {
              this.moveSubpackagesToNewResource(topMost, resource.getResourceSet());
            }
          }
          boolean _equals = topMost.eResource().getURI().toString().equals(topMost.getNsURI());
          boolean _not_2 = (!_equals);
          if (_not_2) {
            this.movePackageToNewResource(topMost, resource.getResourceSet());
          }
        }
      }
    }
  }
  EList<Grammar> _usedGrammars = grammar.getUsedGrammars();
  for (final Grammar usedGrammar : _usedGrammars) {
    this.addAllGrammarsToResource(resource, usedGrammar, visitedGrammars);
  }
}
 
Example 8
public CharSequence grammar(final WizardConfiguration config) {
  CharSequence _xblockexpression = null;
  {
    final Ecore2XtextConfiguration it = config.getEcore2Xtext();
    UniqueNameUtil.clearUniqueNames(it.getDefaultEPackageInfo());
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("// automatically generated by Xtext");
    _builder.newLine();
    _builder.append("grammar ");
    String _name = config.getLanguage().getName();
    _builder.append(_name);
    _builder.append(" with org.eclipse.xtext.common.Terminals");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    {
      Collection<EPackage> _allReferencedEPackages = Ecore2XtextExtensions.allReferencedEPackages(it);
      for(final EPackage it_1 : _allReferencedEPackages) {
        _builder.append("import \"");
        String _nsURI = it_1.getNsURI();
        _builder.append(_nsURI);
        _builder.append("\" ");
        {
          if (((UniqueNameUtil.uniqueName(it_1) != null) && (!Objects.equal(UniqueNameUtil.uniqueName(it_1), "")))) {
            _builder.append("as ");
            String _uniqueName = UniqueNameUtil.uniqueName(it_1);
            _builder.append(_uniqueName);
          }
        }
        _builder.newLineIfNotEmpty();
      }
    }
    _builder.newLine();
    CharSequence _rules = this.rules(it.getRootElementClass());
    _builder.append(_rules);
    _builder.newLineIfNotEmpty();
    {
      List<EClass> _but = this.<EClass>but(Ecore2XtextExtensions.allDispatcherRuleClasses(it), it.getRootElementClass());
      for(final EClass it_2 : _but) {
        _builder.newLine();
        CharSequence _subClassDispatcherRule = this.subClassDispatcherRule(it_2);
        _builder.append(_subClassDispatcherRule);
        _builder.newLineIfNotEmpty();
      }
    }
    {
      List<EClassifier> _but_1 = this.<EClassifier>but(Ecore2XtextExtensions.allConcreteRuleClassifiers(it), it.getRootElementClass());
      for(final EClassifier it_3 : _but_1) {
        _builder.newLine();
        CharSequence _rule = this.rule(it_3);
        _builder.append(_rule);
        _builder.newLineIfNotEmpty();
      }
    }
    _xblockexpression = _builder;
  }
  return _xblockexpression;
}
 
Example 9
@Override
protected String name(EPackage ePackage) {
	return ePackage.getNsURI();
}