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

The following examples show how to use org.eclipse.emf.ecore.EPackage#getESuperPackage() . 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: FragmentFakingEcoreResource.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
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
Source File: GrammarAccessFragment.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
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
Source File: FragmentFakingEcoreResource.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
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
Source File: GrammarAccessFragment2.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
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);
  }
}