Java Code Examples for org.eclipse.emf.ecore.resource.Resource#eSetDeliver()

The following examples show how to use org.eclipse.emf.ecore.resource.Resource#eSetDeliver() . 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: JvmModelGeneratorTest.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
public String generate(final Resource res, final JvmDeclaredType type) {
  String _xblockexpression = null;
  {
    res.eSetDeliver(false);
    EList<EObject> _contents = res.getContents();
    this.builder.<JvmDeclaredType>operator_add(_contents, type);
    res.eSetDeliver(true);
    final InMemoryFileSystemAccess fsa = new InMemoryFileSystemAccess();
    this.generator.doGenerate(res, fsa);
    Map<String, CharSequence> _textFiles = fsa.getTextFiles();
    String _replace = type.getIdentifier().replace(".", "/");
    String _plus = (IFileSystemAccess.DEFAULT_OUTPUT + _replace);
    String _plus_1 = (_plus + ".java");
    _xblockexpression = _textFiles.get(_plus_1).toString();
  }
  return _xblockexpression;
}
 
Example 2
Source File: JvmModelBasedLinkingTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testLinkToParameter() throws Exception {
	XExpression expr = expression("x", false);
	Resource resource = expr.eResource();
	resource.eSetDeliver(false);
	resource.getContents().add(jvmTypesBuilder.toClass(expr, "Foo", cls -> {
		cls.getMembers().add(jvmTypesBuilder.toMethod(expr, "doStuff", stringType(expr), (JvmOperation o) -> {
			o.getParameters().add(jvmTypesBuilder.toParameter(expr, "x", stringType(expr)));
			jvmTypesBuilder.setBody(o, expr);
		}));
	}));
	validationTestHelper.assertNoErrors(expr);
}
 
Example 3
Source File: JvmModelBasedLinkingTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testLinkToParameter_1() throws Exception {
	XFeatureCall expr = (XFeatureCall) expression("x", false);
	Resource resource = expr.eResource();
	resource.eSetDeliver(false);
	resource.getContents().add(jvmTypesBuilder.toClass(expr, "Foo", cls -> {
		cls.getMembers().add(jvmTypesBuilder.toField(expr, "x", stringType(expr)));
		cls.getMembers().add(jvmTypesBuilder.toMethod(expr, "doStuff", stringType(expr), (JvmOperation o) -> {
			o.getParameters().add(jvmTypesBuilder.toParameter(expr, "x", stringType(expr)));
			jvmTypesBuilder.setBody(o, expr);
		}));
	}));
	validationTestHelper.assertNoErrors(expr);
	Assert.assertTrue(expr.getFeature() instanceof JvmFormalParameter);
}
 
Example 4
Source File: JvmModelBasedLinkingTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testLinkToField() throws Exception {
	XFeatureCall expr = (XFeatureCall) expression("x", false);
	Resource resource = expr.eResource();
	resource.eSetDeliver(false);
	resource.getContents().add(jvmTypesBuilder.toClass(expr, "Foo", cls -> {
		cls.getMembers().add(jvmTypesBuilder.toField(expr, "x", stringType(expr)));
		cls.getMembers().add(jvmTypesBuilder.toMethod(expr, "doStuff", stringType(expr), (JvmOperation o) -> {
			o.getParameters().add(jvmTypesBuilder.toParameter(expr, "y", stringType(expr)));
			jvmTypesBuilder.setBody(o, expr);
		}));
	}));
	validationTestHelper.assertNoErrors(expr);
	Assert.assertTrue(expr.getFeature() instanceof JvmField);
}
 
Example 5
Source File: JvmModelBasedLinkingTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testLinkToField_1() throws Exception {
	XFeatureCall expr = (XFeatureCall) expression("x", false);
	Resource resource = expr.eResource();
	resource.eSetDeliver(false);
	resource.getContents().add(jvmTypesBuilder.toClass(expr, "Foo", cls -> {
		cls.getMembers().add(jvmTypesBuilder.toField(expr, "x", stringType(expr)));
		cls.getMembers().add(jvmTypesBuilder.toMethod(expr, "getX", stringType(expr), (JvmOperation o) -> {
			jvmTypesBuilder.setBody(o, expr);
		}));
	}));
	validationTestHelper.assertNoErrors(expr);
	Assert.assertTrue(expr.getFeature() instanceof JvmField);
}
 
Example 6
Source File: ClusteringBuilderState.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Clears the content of the resource set without sending notifications.
 * This avoids unnecessary, explicit unloads.
 */
protected void clearResourceSet(ResourceSet resourceSet) {
    boolean wasDeliver = resourceSet.eDeliver();
    try {
        resourceSet.eSetDeliver(false);
        for (Resource resource : resourceSet.getResources()) {
            resource.eSetDeliver(false);
        }
        resourceSet.getResources().clear();
    } finally {
        resourceSet.eSetDeliver(wasDeliver);
    }
}
 
Example 7
Source File: BuilderParticipant.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Clears the content of the resource set without sending notifications.
 * This avoids unnecessary, explicit unloads.
 * @since 2.7
 */
protected void clearResourceSet(ResourceSet resourceSet) {
	boolean wasDeliver = resourceSet.eDeliver();
	try {
		resourceSet.eSetDeliver(false);
		for (Resource resource : resourceSet.getResources()) {
			resource.eSetDeliver(false);
		}
		resourceSet.getResources().clear();
	} finally {
		resourceSet.eSetDeliver(wasDeliver);
	}
}
 
Example 8
Source File: XtextBuilder.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @param toBeBuilt
 *            the URIs that will be processed in this build run.
 * @param removedProjects
 *            the projects that are no longer considered by XtextBuilders but are yet to be removed from the index.
 * @param monitor
 *            the progress monitor for the build.
 * @param type
 *            indicates the kind of build that is running.
 * 
 * @since 2.18
 */
protected void doBuild(ToBeBuilt toBeBuilt, Set<String> removedProjects, IProgressMonitor monitor, BuildType type) throws CoreException {
	buildLogger.log("Building " + getProject().getName());
	// return early if there's nothing to do.
	// we reuse the isEmpty() impl from BuildData assuming that it doesnT access the ResourceSet which is still null 
	// and would be expensive to create.
	boolean indexingOnly = type == BuildType.RECOVERY;
	if (new BuildData(getProject().getName(), null, toBeBuilt, queuedBuildData, indexingOnly, this::needRebuild, removedProjects).isEmpty())
		return;
	SubMonitor progress = SubMonitor.convert(monitor, 2);
	ResourceSet resourceSet = getResourceSetProvider().get(getProject());
	resourceSet.getLoadOptions().put(ResourceDescriptionsProvider.NAMED_BUILDER_SCOPE, Boolean.TRUE);
	BuildData buildData = new BuildData(getProject().getName(), resourceSet, toBeBuilt, queuedBuildData, indexingOnly, this::needRebuild, removedProjects);
	ImmutableList<Delta> deltas = builderState.update(buildData, progress.split(1));
	if (participant != null && !indexingOnly) {
		SourceLevelURICache sourceLevelURIs = buildData.getSourceLevelURICache();
		Set<URI> sources = sourceLevelURIs.getSources();
		participant.build(new BuildContext(this, resourceSet, deltas, sources, type),
				progress.split(1));
		try {
			getProject().getWorkspace().checkpoint(false);
		} catch(NoClassDefFoundError e) { // guard against broken Eclipse installations / bogus project configuration
			log.error(e.getMessage(), e);
		}
	} else {
		progress.worked(1);
	}
	resourceSet.eSetDeliver(false);
	for (Resource resource : resourceSet.getResources()) {
		resource.eSetDeliver(false);
	}
	resourceSet.getResources().clear();
	resourceSet.eAdapters().clear();
}