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

The following examples show how to use org.eclipse.emf.ecore.EPackage#getESuperPackage() . 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
private void calculateURIFragment(EPackage ePackage, StringBuilder result, Set<EPackage> visited) {
	if (!visited.add(ePackage)) {
		throw new IllegalStateException();
	}
	if (ePackage.getESuperPackage() != null) {
		if (ePackage.eResource() == ePackage.getESuperPackage().eResource()) {
			calculateURIFragment(ePackage.getESuperPackage(), result, visited);
			if (!ePackage.getEClassifiers().isEmpty()) {
				if (result.length() != 0)
					result.append(ePackage.getName()).append('/');
				else
					result.append("//");
			}
		} else {
			result.append("//");
		}
	} else {
		result.append("//");
	}
}
 
Example 2
public void replaceResourceURIsWithNsURIs(Grammar grammar, ResourceSet set) {
	for (AbstractMetamodelDeclaration metamodelDecl : grammar.getMetamodelDeclarations()) {
		EPackage pack = metamodelDecl.getEPackage();
		Resource packResource = pack.eResource();
		if (!packResource.getURI().toString().equals(pack.getNsURI())) {
			ResourceSet packResourceSet = packResource.getResourceSet();
			if (packResourceSet != null) {
				EPackage topMost = pack;
				// we need to be aware of empty subpackages
				while (topMost.getESuperPackage() != null
						&& topMost.getESuperPackage().eResource() == topMost.eResource())
					topMost = topMost.getESuperPackage();
				if (packResource.getContents().contains(topMost) && packResource.getContents().size() == 1) {
					if (!topMost.getEClassifiers().isEmpty())
						packResource.setURI(URI.createURI(topMost.getNsURI()));
					else
						moveSubpackagesToNewResource(topMost, set);
				}
				if (!topMost.eResource().getURI().toString().equals(topMost.getNsURI())) 
					movePackageToNewResource(topMost, set);
			}
		}
	}
}
 
Example 3
private void calculateURIFragment(EPackage ePackage, StringBuilder result, Set<EPackage> visited) {
	if (!visited.add(ePackage)) {
		throw new IllegalStateException();
	}
	if (ePackage.getESuperPackage() != null) {
		if (ePackage.eResource() == ePackage.getESuperPackage().eResource()) {
			calculateURIFragment(ePackage.getESuperPackage(), result, visited);
			if (!ePackage.getEClassifiers().isEmpty()) {
				if (result.length() != 0) {
					result.append(ePackage.getName()).append("/");
				} else {
					result.append("//");
				}
			}
		} else {
			result.append("//");
		}
	} else {
		result.append("//");
	}
}
 
Example 4
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);
  }
}