org.eclipse.emf.ecore.resource.ResourceSet Java Examples

The following examples show how to use org.eclipse.emf.ecore.resource.ResourceSet. 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: DaveDriverImpl.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @generated NOT
 */
@Override
public Profile getProfile ()
{
    if ( this.profile == null )
    {
        final ResourceSet rs = new ResourceSetImpl ();
        final Resource r = rs.createResource ( URI.createURI ( DEFAULT_URI ), "org.eclipse.scada.configuration.world.osgi.profile" );
        try
        {
            r.load ( null );
        }
        catch ( final IOException e )
        {
            throw new RuntimeException ( e );
        }
        this.profile = (Profile)EcoreUtil.getObjectByType ( r.getContents (), ProfilePackage.Literals.PROFILE );
        if ( this.profile == null )
        {
            throw new IllegalStateException ( String.format ( "Resource loaded from %s does not contain an object of type %s", DEFAULT_URI, Profile.class.getName () ) );
        }
    }

    return this.profile;
}
 
Example #2
Source File: FormatLinkingService.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Tries to find {@link Constant} that my be defined in the same formatter or in any formatter that is extended by the current formatter.
 * An appropriate constant should be matched by comparing its name with the desired one.
 *
 * @param resourceSet
 *          to be used for loading
 * @param node
 *          parse subtree for the reference
 * @return A singleton list containing the desired constant, or an empty list if not found.
 */
private List<EObject> getConstant(final ResourceSet resourceSet, final INode node) {
  String constantFullyQualifiedName = NodeModelUtils.getTokenText(node);
  String formatName = URI.createURI(constantFullyQualifiedName).trimFileExtension().toString();
  if (formatName != null) {
    FormatConfiguration result = loadExtendedFormatConfiguration(formatName, resourceSet);
    if (result != null) {
      EList<Constant> constants = result.getConstants();
      for (Constant constant : constants) {
        if (constantFullyQualifiedName.equals(formatName + "." + constant.getName())) {
          return Collections.<EObject> singletonList(constant);
        }
      }
    }
  }
  return Collections.emptyList();
}
 
Example #3
Source File: ReferenceFinder.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void findReferences(final TargetURIs targetURIs, IResourceDescription resourceDescription,
		IResourceAccess resourceAccess, final Acceptor acceptor, final IProgressMonitor monitor) {
	final URI resourceURI = resourceDescription.getURI();
	if (resourceAccess != null && targetURIs.containsResource(resourceURI)) {
		IUnitOfWork.Void<ResourceSet> finder = new IUnitOfWork.Void<ResourceSet>() {
			@Override
			public void process(final ResourceSet state) throws Exception {
				Resource resource = state.getResource(resourceURI, true);
				findReferences(targetURIs, resource, acceptor, monitor);
			}
		};
		resourceAccess.readOnly(resourceURI, finder);
	} else {
		findReferencesInDescription(targetURIs, resourceDescription, resourceAccess, acceptor, monitor);
	}
}
 
Example #4
Source File: BackupUtils.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/** Copy a model based on a number of {@link URI}s. */
public static List<URI> copy(List<URI> sourceURIs, Metamodel metamodel,
	URIMapper mapper) throws IOException {
	final List<URI> targetURIs = new ArrayList<URI>();
	final ResourceSet model = ResourceUtils.loadResourceSet(sourceURIs, metamodel
		.getEPackages());
	for (final Resource resource : model.getResources()) {
		if (resource.getURI() == null
			|| resource.getURI().isPlatformPlugin()) {
			continue;
		}
		final URI targetURI = mapper.map(resource.getURI());
		if (targetURI != null) {
			resource.setURI(targetURI);
			targetURIs.add(targetURI);
		}
	}
	ResourceUtils.saveResourceSet(model, null);
	return targetURIs;
}
 
Example #5
Source File: AbstractTemplatesTestSuite.java    From M2Doc with Eclipse Public License 1.0 6 votes vote down vote up
protected ResourceSet getResourceSetForModel(final List<Exception> exceptions) {
    final ResourceSet rs = new ResourceSetImpl();

    final XMIResourceFactoryImpl xmiResourceFactory = new XMIResourceFactoryImpl();
    rs.getResourceFactoryRegistry().getExtensionToFactoryMap().put("ecore", xmiResourceFactory);
    rs.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi", xmiResourceFactory);
    rs.getResourceFactoryRegistry().getExtensionToFactoryMap().put(GenconfUtils.GENCONF_EXTENSION_FILE,
            xmiResourceFactory);
    rs.getResourceFactoryRegistry().getExtensionToFactoryMap().put("uml", xmiResourceFactory);

    final ResourceSet res = M2DocUtils.createResourceSetForModels(exceptions, generation, rs,
            GenconfUtils.getOptions(generation));
    res.getURIConverter().getURIHandlers().add(0, uriHandler);

    return res;
}
 
Example #6
Source File: JSONModelUtils.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Serializes the given {@link JSONDocument} using the Xtext serialization facilities provided by the JSON language.
 */
public static String serializeJSON(JSONDocument document) {
	ISerializer jsonSerializer = N4LanguageUtils.getServiceForContext(FILE_EXTENSION, ISerializer.class).get();
	ResourceSet resourceSet = N4LanguageUtils.getServiceForContext(FILE_EXTENSION, ResourceSet.class).get();

	// Use temporary Resource as AbstractFormatter2 implementations can only format
	// semantic elements that are contained in a Resource.
	Resource temporaryResource = resourceSet.createResource(URIUtils.toFileUri("__synthetic." + FILE_EXTENSION));
	temporaryResource.getContents().add(document);

	// create string writer as serialization output
	StringWriter writer = new StringWriter();

	// enable formatting as serialization option
	SaveOptions serializerOptions = SaveOptions.newBuilder().format().getOptions();
	try {
		jsonSerializer.serialize(document, writer, serializerOptions);
		return writer.toString();
	} catch (IOException e) {
		throw new RuntimeException("Failed to serialize JSONDocument " + document, e);
	}
}
 
Example #7
Source File: LiveShadowedAllContainerStateTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testEmptyProject() {
  try {
    final IProject project = IResourcesSetupUtil.createProject("MyProject");
    IResourcesSetupUtil.addNature(project, XtextProjectHelper.NATURE_ID);
    final ResourceSet rs = this.liveScopeResourceSetProvider.get(project);
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("container MyProject isEmpty=true {");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final String expected = _builder.toString();
    Assert.assertEquals(expected, this.formatContainers(rs));
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #8
Source File: TemporaryResourceProvider.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
public <Result> Result useTemporaryResource(
		ResourceSet resourceSet, Grammar language, 
		AbstractRule rootRule, String content, IUnitOfWork<Result, XtextResource> runnable) {
	XtextResource resource = languageRegistry.createTemporaryResourceIn(language, resourceSet);
	if (rootRule != null)
		PartialParser.assignRootRule(resource, (ParserRule) rootRule);
	try {
		resource.load(new StringInputStream(content, resource.getEncoding()), null);
		return runnable.exec(resource);
	} catch(Exception e) {
		throw new RuntimeException(e);
	} finally {
		if (resource != null) {
			if (resource.isLoaded())
				resource.unload();
			resourceSet.getResources().remove(resource);
		}
	}
}
 
Example #9
Source File: ExternalLibraryBuilder.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Deletes all entries in the Xtext index that start with one of the given project URIs will be cleaned from the
 * index.
 *
 * @param toBeWiped
 *            URIs of project roots
 */
public void wipeURIsFromIndex(IProgressMonitor monitor, Collection<FileURI> toBeWiped) {
	Set<String> toBeWipedStrings = new HashSet<>();
	for (FileURI toWipe : toBeWiped) {
		toBeWipedStrings.add(toWipe.toString());
		N4JSProjectName projectName = toWipe.getProjectName();
		validatorExtension.clearAllMarkersOfExternalProject(projectName);
	}

	ResourceSet resourceSet = core.createResourceSet(Optional.absent());
	IResourceDescriptions index = core.getXtextIndex(resourceSet);

	Set<URI> toBeRemoved = new HashSet<>();
	for (IResourceDescription res : index.getAllResourceDescriptions()) {
		URI resUri = res.getURI();
		String resUriString = resUri.toString();
		for (String toWipeProject : toBeWipedStrings) {
			if (resUriString.startsWith(toWipeProject)) {
				toBeRemoved.add(resUri);
				break;
			}
		}
	}

	builderState.clean(toBeRemoved, monitor);
}
 
Example #10
Source File: BpmnDeployer.java    From fixflow with Apache License 2.0 6 votes vote down vote up
private ResourceSet getResourceSet() {
	// TODO Auto-generated method stub
	ResourceSet resourceSet = new ResourceSetImpl();
	(EPackage.Registry.INSTANCE).put("http://www.omg.org/spec/BPMN/20100524/MODEL", Bpmn2Package.eINSTANCE);
	(EPackage.Registry.INSTANCE).put("http://www.founderfix.com/fixflow", FixFlowPackage.eINSTANCE);
	(EPackage.Registry.INSTANCE).put("http://www.omg.org/spec/DD/20100524/DI", DiPackage.eINSTANCE);
	(EPackage.Registry.INSTANCE).put("http://www.omg.org/spec/DD/20100524/DC", DcPackage.eINSTANCE);
	(EPackage.Registry.INSTANCE).put("http://www.omg.org/spec/BPMN/20100524/DI", BpmnDiPackage.eINSTANCE);
	FixFlowPackage.eINSTANCE.eClass();

	FixFlowPackage xxxPackage = FixFlowPackage.eINSTANCE;
	EPackage.Registry.INSTANCE.put(xxxPackage.getNsURI(), xxxPackage);
	Bpmn2ResourceFactoryImpl ddd = new Bpmn2ResourceFactoryImpl();
	Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("fixflow", ddd);

	resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("bpmn", ddd);

	resourceSet.getPackageRegistry().put(xxxPackage.getNsURI(), xxxPackage);

	Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("bpmn", ddd);
	
	return resourceSet;
}
 
Example #11
Source File: AbstractHierarchyBuilderTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected ResourceSet createResourceSet(@Extension final AbstractHierarchyBuilderTest.HierarchyBuilderTestConfiguration configuration) {
  try {
    final XtextResourceSet resourceSet = this.resourceSetProvider.get();
    for (final Pair<String, String> model : configuration.models) {
      {
        final Resource resource = resourceSet.createResource(URI.createURI(model.getKey()));
        String _value = model.getValue();
        LazyStringInputStream _lazyStringInputStream = new LazyStringInputStream(_value, "UTF-8");
        resource.load(_lazyStringInputStream, null);
        this._validationTestHelper.assertNoIssues(resource);
      }
    }
    return resourceSet;
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #12
Source File: PapyrusModelCreatorTest.java    From txtUML with Eclipse Public License 1.0 6 votes vote down vote up
private void createUMLFile(URI uri, String modelname){
	Model model = UMLFactory.eINSTANCE.createModel();
       
	model.setName(modelname);

   	ResourceSet resourceSet = new ResourceSetImpl();
 		resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
       
       resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(
 				UMLResource.FILE_EXTENSION,
 				UMLResource.Factory.INSTANCE
 			);
       
       Resource modelResource = resourceSet.createResource(uri);
       modelResource.getContents().add(model);
       try {
		modelResource.save(null);
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
Example #13
Source File: ModelLoader.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
public T load ( final URI uri, final String contentTypeId ) throws IOException
{
    final ResourceSet rs = new ResourceSetImpl ();
    final Resource r = rs.createResource ( uri, contentTypeId );
    r.load ( null );

    for ( final Object o : r.getContents () )
    {
        if ( this.clazz.isAssignableFrom ( o.getClass () ) )
        {
            return this.clazz.cast ( o );
        }
    }

    throw new IllegalStateException ( String.format ( "Model %s does not contain an object of type %s", uri, this.clazz ) );
}
 
Example #14
Source File: StandaloneBuilder.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected List<URI> collectResources(Iterable<String> roots, ResourceSet resourceSet) {
	String extensions = Joiner.on("|").join(languages.keySet());
	NameBasedFilter nameBasedFilter = new NameBasedFilter();
	// TODO test with whitespaced file extensions
	nameBasedFilter.setRegularExpression(".*\\.(?:(" + extensions + "))$");
	List<URI> resources = new ArrayList<>();
	Multimap<String, URI> modelsFound = new PathTraverser().resolvePathes(IterableExtensions.toList(roots),
			(URI input) -> {
				boolean matches = nameBasedFilter.matches(input);
				if (matches) {
					forceDebugLog("Adding file \'" + input + "\'");
					resources.add(input);
				}
				return matches;
			});
	modelsFound.asMap().forEach((String uri, Collection<URI> resource) -> {
		File file = new File(uri);
		if (resource != null && !file.isDirectory() && file.getName().endsWith(".jar")) {
			registerBundle(file);
		}
	});
	return resources;
}
 
Example #15
Source File: SiriusServiceConfigurator.java    From M2Doc with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Set<IService> getServices(IReadOnlyQueryEnvironment queryEnvironment, ResourceSet resourceSetForModels,
        Map<String, String> options) {
    final Set<IService> res = new LinkedHashSet<>();

    final String sessionURIStr = options.get(M2DocSiriusUtils.SIRIUS_SESSION_OPTION);
    if (sessionURIStr != null) {
        URI sessionURI = URI.createURI(sessionURIStr, false);
        final String genconfURIStr = options.get(GenconfUtils.GENCONF_URI_OPTION);
        if (genconfURIStr != null) {
            sessionURI = sessionURI.resolve(URI.createURI(genconfURIStr));
        }
        if (URIConverter.INSTANCE.exists(sessionURI, Collections.emptyMap())) {
            final Session session = SessionManager.INSTANCE.getSession(sessionURI, new NullProgressMonitor());
            final boolean forceRefresh = Boolean.valueOf(options.get(M2DocSiriusUtils.SIRIUS_FORCE_REFRESH));
            final M2DocSiriusServices serviceInstance = new M2DocSiriusServices(session, forceRefresh);
            res.addAll(ServiceUtils.getServices(queryEnvironment, serviceInstance));
            services.put(queryEnvironment, serviceInstance);
        }
    }

    return res;
}
 
Example #16
Source File: EPackageChooser.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected List<EPackageInfo> createEPackageInfosFromGenModel(URI genModelURI) {
	ResourceSet resourceSet = createResourceSet(genModelURI);
	Resource resource = resourceSet.getResource(genModelURI, true);
	List<EPackageInfo> ePackageInfos = Lists.newArrayList();
	for (TreeIterator<EObject> i = resource.getAllContents(); i.hasNext();) {
		EObject next = i.next();
		if (next instanceof GenPackage) {
			GenPackage genPackage = (GenPackage) next;
			EPackage ePackage = genPackage.getEcorePackage();
			URI importURI;
			if(ePackage.eResource() == null) {
				importURI = URI.createURI(ePackage.getNsURI());
			} else {
				importURI = ePackage.eResource().getURI();
			}
			EPackageInfo ePackageInfo = new EPackageInfo(ePackage, importURI, genModelURI, genPackage
					.getQualifiedPackageInterfaceName(), genPackage.getGenModel().getModelPluginID());
			ePackageInfos.add(ePackageInfo);
		} else if (!(next instanceof GenModel)) {
			i.prune();
		}
	}
	return ePackageInfos;
}
 
Example #17
Source File: MetaService.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
private void addCrossReferenceAdapterToResource(Model model, ECrossReferenceAdapter crossReferenceAdapter) {
	ResourceSet resourceSet = new ResourceSetImpl();
	URI uri = URI.createURI(MetaService.KNOWAGE_MODEL_URI);
	Resource resource = resourceSet.createResource(uri);
	resource.getContents().add(model);

	resource.getResourceSet().eAdapters().add(crossReferenceAdapter);
}
 
Example #18
Source File: Declarators.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public Declarators.DeclaratorsData getDeclaratorData(final TargetURIs targetURIs, final IReferenceFinder.IResourceAccess resourceAccess) {
  Declarators.DeclaratorsData result = targetURIs.<Declarators.DeclaratorsData>getUserData(Declarators.KEY);
  if ((result != null)) {
    return result;
  }
  final HashSet<QualifiedName> declaratorNames = CollectionLiterals.<QualifiedName>newHashSet();
  final Consumer<URI> _function = (URI uri) -> {
    final IUnitOfWork<Object, ResourceSet> _function_1 = (ResourceSet it) -> {
      Object _xblockexpression = null;
      {
        final Consumer<URI> _function_2 = (URI objectURI) -> {
          final EObject object = it.getEObject(objectURI, true);
          if ((object != null)) {
            final JvmType type = EcoreUtil2.<JvmType>getContainerOfType(object, JvmType.class);
            if ((type != null)) {
              QualifiedName _lowerCase = this.nameConverter.toQualifiedName(type.getIdentifier()).toLowerCase();
              declaratorNames.add(_lowerCase);
              QualifiedName _lowerCase_1 = this.nameConverter.toQualifiedName(type.getQualifiedName('.')).toLowerCase();
              declaratorNames.add(_lowerCase_1);
            }
          }
        };
        targetURIs.getEObjectURIs(uri).forEach(_function_2);
        _xblockexpression = null;
      }
      return _xblockexpression;
    };
    resourceAccess.<Object>readOnly(uri, _function_1);
  };
  targetURIs.getTargetResourceURIs().forEach(_function);
  Declarators.DeclaratorsData _declaratorsData = new Declarators.DeclaratorsData(declaratorNames);
  result = _declaratorsData;
  targetURIs.<Declarators.DeclaratorsData>putUserData(Declarators.KEY, result);
  return result;
}
 
Example #19
Source File: SlotEntry.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected List<EObject> findEObjectsOfType(Set<EClass> eClasses, IResourceDescriptions resourceDescriptions,
		ResourceSet resourceSet) {
	List<EObject> elements = Lists.newArrayList();
	Iterable<IResourceDescription> descriptions = resourceDescriptions.getAllResourceDescriptions();
	for (IResourceDescription resDesc : descriptions) {
		Iterable<IEObjectDescription> objects = resDesc.getExportedObjects();
		for (IEObjectDescription description : objects) {
			if (matches(eClasses, description))
				elements.add(resourceSet.getEObject(description.getEObjectURI(), true));
		}
	}
	return elements;
}
 
Example #20
Source File: N4JSRuntimeCore.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
private void installIndex(ResourceSet resourceSet) {
	// Fill index
	ResourceDescriptionsData index = new OrderedResourceDescriptionsData(
			Collections.<IResourceDescription> emptyList());
	List<Resource> resources = Lists.newArrayList(resourceSet.getResources());
	for (Resource resource : resources) {
		index(resource, resource.getURI(), index);
	}
	Adapter existing = EcoreUtil.getAdapter(resourceSet.eAdapters(), ResourceDescriptionsData.class);
	if (existing != null) {
		resourceSet.eAdapters().remove(existing);
	}
	ResourceDescriptionsData.ResourceSetAdapter.installResourceDescriptionsData(resourceSet, index);
}
 
Example #21
Source File: XtextCallHierarchyBuilderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void testBuildHierarchy(final Procedure1<? super AbstractHierarchyBuilderTest.HierarchyBuilderTestConfiguration> configurator) {
  final Procedure1<AbstractHierarchyBuilderTest.HierarchyBuilderTestConfiguration> _function = (AbstractHierarchyBuilderTest.HierarchyBuilderTestConfiguration it) -> {
    final Function1<ResourceSet, IHierarchyBuilder> _function_1 = (ResourceSet resourceSet) -> {
      final XtextCallHierarchyBuilder callHierarchyBuilder = this.<XtextCallHierarchyBuilder>configureBuilderWith(this.callHierarchyBuilderProvider.get(), resourceSet);
      callHierarchyBuilder.setHierarchyType(ICallHierarchyBuilder.CallHierarchyType.CALLER);
      return callHierarchyBuilder;
    };
    it.setHierarchyBuilderProvider(_function_1);
    configurator.apply(it);
  };
  super.testBuildHierarchy(_function);
}
 
Example #22
Source File: CodeBuilderFactory.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Create the appender for a Sarl SarlAnnotationType.
 * @param name the name of the SarlAnnotationType
 * @param resourceSet the set of the resources that must be used for
 *    containing the generated resource, and resolving types from names.
 * @return the appender.
 */
@Pure
public SarlAnnotationTypeSourceAppender buildSarlAnnotationType(String name, ResourceSet resourceSet) {
	SarlAnnotationTypeSourceAppender a = new SarlAnnotationTypeSourceAppender(createSarlAnnotationType(name, resourceSet));
	getInjector().injectMembers(a);
	return a;
}
 
Example #23
Source File: GenerateWeb3Contract.java    From uml2solidity with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * This can be used to update the resource set's package registry with all needed EPackages.
 * 
 * @param resourceSet
 *            The resource set which registry has to be updated.
 * @generated
 */
@Override
public void registerPackages(ResourceSet resourceSet) {
    super.registerPackages(resourceSet);
    if (!isInWorkspace(org.eclipse.uml2.uml.UMLPackage.class)) {
        resourceSet.getPackageRegistry().put(org.eclipse.uml2.uml.UMLPackage.eINSTANCE.getNsURI(), org.eclipse.uml2.uml.UMLPackage.eINSTANCE);
    }
    
    /*
     * If you want to change the content of this method, do NOT forget to change the "@generated"
     * tag in the Javadoc of this method to "@generated NOT". Without this new tag, any compilation
     * of the Acceleo module with the main template that has caused the creation of this class will
     * revert your modifications.
     */
    
    /*
     * If you need additional package registrations, you can register them here. The following line
     * (in comment) is an example of the package registration for UML.
     * 
     * You can use the method  "isInWorkspace(Class c)" to check if the package that you are about to
     * register is in the workspace.
     * 
     * To register a package properly, please follow the following conventions:
     *
     * If the package is located in another plug-in, already installed in Eclipse. The following content should
     * have been generated at the beginning of this method. Do not register the package using this mechanism if
     * the metamodel is located in the workspace.
     *  
     * if (!isInWorkspace(UMLPackage.class)) {
     *     // The normal package registration if your metamodel is in a plugin.
     *     resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
     * }
     * 
     * If the package is located in another project in your workspace, the plugin containing the package has not
     * been register by EMF and Acceleo should register it automatically. If you want to use the generator in
     * stand alone, the regular registration (seen a couple lines before) is needed.
     * 
     * To learn more about Package Registration, have a look at the Acceleo documentation (Help -> Help Contents).
     */
}
 
Example #24
Source File: EcorePackageRenameStrategy.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Change the package name.
 *
 * @param newName the new name.
 * @param resourceSet the set of resource to use.
 */
protected void setPackageName(String newName, ResourceSet resourceSet) {
	final EObject object = resourceSet.getEObject(this.uriProvider.apply(resourceSet), true);
	if (object instanceof SarlScript) {
		((SarlScript) object).setPackage(newName);
	} else {
		throw new RefactoringException("SARL script not loaded."); //$NON-NLS-1$
	}
}
 
Example #25
Source File: RawTypeHelper.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected void enhanceCompoundReference(List<LightweightTypeReference> references,
		CompoundTypeReference result, ResourceSet resourceSet) {
	if (references.isEmpty()) {
		throw new IllegalStateException("References may not be empty");
	}
	for(LightweightTypeReference component: references) {
		result.addComponent(component.accept(this, resourceSet));
	}
}
 
Example #26
Source File: RawTypeHelper.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected List<JvmType> doVisitParameterizedTypeReference(ParameterizedTypeReference reference, ResourceSet resourceSet) {
	JvmType type = reference.getType();
	if (!type.eIsProxy()) {
		if (type instanceof JvmTypeParameter) {
			return getRawTypesFromConstraints(reference.getOwner(), (JvmTypeParameter) type, resourceSet);
		}
		return Collections.singletonList(type);
	}
	return Collections.emptyList();
}
 
Example #27
Source File: JSDoc2SpecProcessor.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @throws InterruptedException
 *             thrown when user cancels the operation
 * @see N4JSDReader#readN4JSDs(Collection, Function, SubMonitorMsg)
 */
public Collection<SpecInfo> readN4JSDs(Collection<IN4JSProject> projects,
		Function<IN4JSProject, ResourceSet> resSetProvider, SubMonitorMsg monitor) throws InterruptedException {

	SubMonitorMsg sub = monitor.convert(100 * (projects.size() + 2));
	n4jsdReader.issueAcceptor = this.issueAcceptor;
	return n4jsdReader.readN4JSDs(projects, resSetProvider, sub);
}
 
Example #28
Source File: AbstractLiveContainerTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected URI computeUnusedUri(ResourceSet resourceSet) {
	String name = "__synthetic";
	for (int i = 0; i < Integer.MAX_VALUE; i++) {
		URI syntheticUri = URI.createURI(name + i + "." + parser.fileExtension);
		syntheticUri = resourceSet.getURIConverter().normalize(syntheticUri);
		if (resourceSet.getResource(syntheticUri, false) == null)
			return syntheticUri;
	}
	throw new IllegalStateException();
}
 
Example #29
Source File: N4JSRuntimeCore.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
private void createAllResourcesWorkspace(ResourceSet resourceSet) {
	final Set<URI> uris = newHashSet();
	for (IN4JSProject project : findAllProjects()) {
		project.getSourceContainers().forEach(sc -> {
			for (URI sourceFile : sc) {
				if (isN4File(sourceFile) && uris.add(sourceFile)) {
					resourceSet.createResource(sourceFile);
				}
			}
		});
	}
}
 
Example #30
Source File: ResourceDescriptionsData.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public static void installResourceDescriptionsData(ResourceSet resourceSet, ResourceDescriptionsData data) {
	if (findResourceDescriptionsData(resourceSet) != null) {
		throw new IllegalStateException("Resource description data is already installed.");
	}
	ResourceSetAdapter resourceSetAdapter = new ResourceSetAdapter(data);
	resourceSet.eAdapters().add(resourceSetAdapter);
}