Java Code Examples for org.eclipse.xtext.EcoreUtil2#resolveLazyCrossReferences()

The following examples show how to use org.eclipse.xtext.EcoreUtil2#resolveLazyCrossReferences() . 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: ActiveAnnotationsProcessingInIDETest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void assertProcessing(final Pair<String, String> macroContent, final Pair<String, String> clientContent, final Procedure1<? super CompilationUnitImpl> expectations) {
  try {
    this.macroFile = this.newSource(ActiveAnnotationsProcessingInIDETest.macroProject, macroContent.getKey(), macroContent.getValue().toString());
    final int lidx = macroContent.getKey().lastIndexOf("/");
    if ((lidx != (-1))) {
      this.exportedPackage = macroContent.getKey().substring(0, lidx).replace("/", ".");
      boolean _addExportedPackages = WorkbenchTestHelper.addExportedPackages(ActiveAnnotationsProcessingInIDETest.macroProject.getProject(), this.exportedPackage);
      if (_addExportedPackages) {
        IResourcesSetupUtil.reallyWaitForAutoBuild();
      }
    }
    this.clientFile = this.newSource(ActiveAnnotationsProcessingInIDETest.userProject, clientContent.getKey(), clientContent.getValue().toString());
    IResourcesSetupUtil.waitForBuild();
    final ResourceSet resourceSet = this.resourceSetProvider.get(ActiveAnnotationsProcessingInIDETest.userProject.getProject());
    final Resource resource = resourceSet.getResource(URI.createPlatformResourceURI(this.clientFile.getFullPath().toString(), true), true);
    EcoreUtil2.resolveLazyCrossReferences(resource, CancelIndicator.NullImpl);
    this.validator.validate(resource, CheckMode.FAST_ONLY, CancelIndicator.NullImpl);
    final CompilationUnitImpl unit = this.compilationUnitProvider.get();
    unit.setXtendFile(IterableExtensions.<XtendFile>head(Iterables.<XtendFile>filter(resource.getContents(), XtendFile.class)));
    expectations.apply(unit);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 2
Source File: DefaultResourceDescription.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
protected List<IReferenceDescription> computeReferenceDescriptions() {
	final List<IReferenceDescription> referenceDescriptions = Lists.newArrayList();
	IAcceptor<IReferenceDescription> acceptor = new IAcceptor<IReferenceDescription>() {
		@Override
		public void accept(IReferenceDescription referenceDescription) {
			referenceDescriptions.add(referenceDescription);
		}
	};
	EcoreUtil2.resolveLazyCrossReferences(resource, CancelIndicator.NullImpl);
	Map<EObject, IEObjectDescription> eObject2exportedEObjects = createEObject2ExportedEObjectsMap(getExportedObjects());
	TreeIterator<EObject> contents = EcoreUtil.getAllProperContents(this.resource, true);
	while (contents.hasNext()) {
		EObject eObject = contents.next();
		URI exportedContainerURI = findExportedContainerURI(eObject, eObject2exportedEObjects);
		if (!strategy.createReferenceDescriptions(eObject, exportedContainerURI, acceptor))
			contents.prune();
	}
	return referenceDescriptions;
}
 
Example 3
Source File: DefaultReferenceDescriptionTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testgetReferenceDescriptions() throws Exception {
	with(new LangATestLanguageStandaloneSetup());
	XtextResource targetResource = getResource("type C", "bar.langatestlanguage");
	EObject typeC = targetResource.getContents().get(0).eContents().get(0);
	XtextResource resource = (XtextResource) targetResource.getResourceSet().createResource(URI.createURI("foo.langatestlanguage"));
	resource.load(new StringInputStream("type A extends C type B extends A"), null);
	EcoreUtil2.resolveLazyCrossReferences(resource, CancelIndicator.NullImpl);
	IResourceDescription resDesc = resource.getResourceServiceProvider().getResourceDescriptionManager().getResourceDescription(resource);
	Iterable<IReferenceDescription> descriptions = resDesc.getReferenceDescriptions();
	Collection<IReferenceDescription> collection = Lists.newArrayList(descriptions);
	assertEquals(1,collection.size());
	IReferenceDescription refDesc = descriptions.iterator().next();
	Main m = (Main) resource.getParseResult().getRootASTElement();
	assertEquals(m.getTypes().get(0),resource.getResourceSet().getEObject(refDesc.getSourceEObjectUri(),false));
	assertEquals(typeC, resource.getResourceSet().getEObject(refDesc.getTargetEObjectUri(),false));
	assertEquals(-1,refDesc.getIndexInList());
	assertEquals(LangATestLanguagePackage.Literals.TYPE__EXTENDS,refDesc.getEReference());
}
 
Example 4
Source File: DefaultReferenceDescriptionTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testgetReferenceDescriptionForMultiValue() throws Exception {
	with(new LangATestLanguageStandaloneSetup());
	XtextResource targetResource = getResource("type C type D", "bar.langatestlanguage");
	EObject typeC = targetResource.getContents().get(0).eContents().get(0);
	EObject typeD = targetResource.getContents().get(0).eContents().get(1);
	XtextResource resource = (XtextResource) targetResource.getResourceSet().createResource(URI.createURI("foo.langatestlanguage"));
	resource.load(new StringInputStream("type A implements B,C,D type B"), null);
	EcoreUtil2.resolveLazyCrossReferences(resource, CancelIndicator.NullImpl);
	IResourceDescription resDesc = resource.getResourceServiceProvider().getResourceDescriptionManager().getResourceDescription(resource);
	Iterable<IReferenceDescription> descriptions = resDesc.getReferenceDescriptions();
	Collection<IReferenceDescription> collection = Lists.newArrayList(descriptions);
	assertEquals(2,collection.size());
	Iterator<IReferenceDescription> iterator = descriptions.iterator();
	IReferenceDescription refDesc1 = iterator.next();
	IReferenceDescription refDesc2 = iterator.next();
	Main m = (Main) resource.getParseResult().getRootASTElement();
	assertEquals(m.getTypes().get(0),resource.getResourceSet().getEObject(refDesc1.getSourceEObjectUri(),false));
	assertEquals(typeC,resource.getResourceSet().getEObject(refDesc1.getTargetEObjectUri(),false));
	assertEquals(1,refDesc1.getIndexInList());
	assertEquals(LangATestLanguagePackage.Literals.TYPE__IMPLEMENTS,refDesc1.getEReference());
	assertEquals(m.getTypes().get(0),resource.getResourceSet().getEObject(refDesc2.getSourceEObjectUri(),false));
	assertEquals(typeD,resource.getResourceSet().getEObject(refDesc2.getTargetEObjectUri(),false));
	assertEquals(2,refDesc2.getIndexInList());
	assertEquals(LangATestLanguagePackage.Literals.TYPE__IMPLEMENTS,refDesc2.getEReference());
}
 
Example 5
Source File: ResourceDescription2.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected List<IReferenceDescription> computeReferenceDescriptions() {
  final ImmutableList.Builder<IReferenceDescription> referenceDescriptions = ImmutableList.builder();
  EcoreUtil2.resolveLazyCrossReferences(getResource(), CancelIndicator.NullImpl);
  Map<EObject, IEObjectDescription> eObject2exportedEObjects = createEObject2ExportedEObjectsMap(getExportedObjects());
  TreeIterator<EObject> contents = EcoreUtil.getAllProperContents(getResource(), true);
  while (contents.hasNext()) {
    EObject eObject = contents.next();
    URI exportedContainerURI = findExportedContainerURI(eObject, eObject2exportedEObjects);
    if (!strategy.createReferenceDescriptions(eObject, exportedContainerURI, referenceDescriptions::add)) {
      contents.prune();
    }
  }
  if (strategy instanceof AbstractResourceDescriptionStrategy) {
    ((AbstractResourceDescriptionStrategy) strategy).createImplicitReferenceDescriptions(getResource(), referenceDescriptions::add);
  }
  return referenceDescriptions.build();
}
 
Example 6
Source File: XpectN4JSES5GeneratorHelper.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Compiles provided Script. Can replace backslashes with single quote (for windows command line issues)
 *
 * @param depRoot
 *            script to transpile
 * @param options
 *            the {@link GeneratorOption}s to use during compilation.
 * @param replaceQuotes
 *            should replace quotes (only for windows)
 * @return string representation of compilation result
 */
public String compile(Script depRoot, GeneratorOption[] options, boolean replaceQuotes) {
	final Resource resource = depRoot.eResource();
	EcoreUtil2.resolveLazyCrossReferences(resource, CancelIndicator.NullImpl);
	final ISubGenerator generator = getGeneratorForResource(resource);
	String compileResultStr = generator.getCompileResultAsText(depRoot, options);
	if (replaceQuotes) {
		// Windows Node.js has problems with " as it interprets it as ending of script to execute
		compileResultStr = compileResultStr.replace("\"", "'");
	}
	return compileResultStr;
}
 
Example 7
Source File: XStatefulIncrementalBuilder.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
private Delta buildClustured(Resource resource,
		XSource2GeneratedMapping newSource2GeneratedMapping,
		XIndexer.XIndexResult result) {

	CancelIndicator cancelIndicator = request.getCancelIndicator();
	operationCanceledManager.checkCanceled(cancelIndicator);

	// trigger init
	resource.getContents();
	EcoreUtil2.resolveLazyCrossReferences(resource, CancelIndicator.NullImpl);
	operationCanceledManager.checkCanceled(cancelIndicator);

	URI source = resource.getURI();
	IResourceServiceProvider serviceProvider = getResourceServiceProvider(resource);
	IResourceDescription.Manager manager = serviceProvider.getResourceDescriptionManager();
	IResourceValidator resourceValidator = serviceProvider.getResourceValidator();

	IResourceDescription description = manager.getResourceDescription(resource);
	SerializableResourceDescription copiedDescription = SerializableResourceDescription.createCopy(description);
	result.getNewIndex().addDescription(source, copiedDescription);
	operationCanceledManager.checkCanceled(cancelIndicator);

	if (request.canValidate()) {
		List<Issue> issues = resourceValidator.validate(resource, CheckMode.ALL, cancelIndicator);
		List<LSPIssue> lspIssues = lspIssueConverter.convertToLSPIssues(resource, issues, cancelIndicator);
		operationCanceledManager.checkCanceled(cancelIndicator);
		request.setResultIssues(request.getProjectName(), source, lspIssues);
		boolean proceedGenerate = !request.containsValidationErrors(source);

		if (proceedGenerate) {
			operationCanceledManager.checkCanceled(cancelIndicator);
			generate(resource, newSource2GeneratedMapping, serviceProvider);
		} else {
			removeGeneratedFiles(resource.getURI(), newSource2GeneratedMapping);
		}
	}

	IResourceDescription old = context.getOldState().getResourceDescriptions().getResourceDescription(source);
	return manager.createDelta(old, copiedDescription);
}
 
Example 8
Source File: OpenFileContext.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
public void resolveOpenFile(CancelIndicator cancelIndicator) {
	// resolve
	EcoreUtil2.resolveLazyCrossReferences(mainResource, cancelIndicator);
	// update dirty state
	updateSharedDirtyState();
	// notify open file listeners
	parent.onDidRefreshOpenFile(this, cancelIndicator);
}
 
Example 9
Source File: DefaultResourceDescription.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Iterable<QualifiedName> getImportedNames() {
	EcoreUtil2.resolveLazyCrossReferences(resource, CancelIndicator.NullImpl);
	ImportedNamesAdapter adapter = ImportedNamesAdapter.find(getResource());
	if (adapter != null) {
		ImmutableSet<QualifiedName> result = ImmutableSet.copyOf(adapter.getImportedNames());
		return result;
	}
	return Collections.emptySet();
}
 
Example 10
Source File: AbstractValidationTest.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void beforeApplyAssertions(final XtextTestSource testSource) {
  super.beforeApplyAssertions(testSource);
  EObject root = testSource.getModel();
  // Get all diagnostics of the current testing file
  EcoreUtil2.resolveLazyCrossReferences(root.eResource(), CancelIndicator.NullImpl);
  fileDiagnostics = validate(root);
  getUnexpectedDiagnostics().addAll(fileDiagnostics.getChildren());
  getUnexpectedResourceDiagnostics().addAll(root.eResource().getErrors());
  getUnexpectedResourceDiagnostics().addAll(root.eResource().getWarnings());
}
 
Example 11
Source File: GamlResourceValidator.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
@Override
public List<Issue> validate(final Resource resource, final CheckMode mode, final CancelIndicator indicator) {
	// DEBUG.OUT("GamlResourceValidato begginning validation job of " + resource.getURI().lastSegment());
	try (final Collector.AsList<Issue> result = Collector.getList();) {
		final IAcceptor<Issue> acceptor = t -> {
			if (t.getMessage() != null && !t.getMessage().isEmpty()) {
				result.add(t);
			}
		};
		// We resolve the cross references
		EcoreUtil2.resolveLazyCrossReferences(resource, indicator);
		// DEBUG.OUT("Cross references resolved for " + resource.getURI().lastSegment());
		// And collect the syntax / linking issues
		for (int i = 0; i < resource.getErrors().size(); i++) {
			converter.convertResourceDiagnostic(resource.getErrors().get(i), Severity.ERROR, acceptor);
		}

		// We then ask the resource to validate itself
		final GamlResource r = (GamlResource) resource;
		r.validate();
		// DEBUG.OUT("Resource has been validated: " + resource.getURI().lastSegment());
		// And collect the semantic errors from its error collector
		for (final Diagnostic d : errorTranslator.translate(r.getValidationContext(), r, mode).getChildren()) {
			converter.convertValidatorDiagnostic(d, acceptor);
		}
		GamlResourceServices.discardValidationContext(r);
		// DEBUG.OUT("Validation context has been discarded: " + resource.getURI().lastSegment());
		return result.items();
	}
}
 
Example 12
Source File: XtextComparisonExpressionLoader.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
public Operation_Compare resolveProxies(final Resource resource, final ResourceSet resourceSet) {
    EcoreUtil2.resolveLazyCrossReferences(resource, CancelIndicator.NullImpl);
    final Operation_Compare compareOp = (Operation_Compare) resource.getContents().get(0);
    final List<Expression_ProcessRef> allRefs = modelSearch.getAllItemsOfType(compareOp, Expression_ProcessRef.class);
    for (final Expression_ProcessRef ref : allRefs) {
        final EObject proxy = ref.getValue();
        if (proxy.eIsProxy()) {
            ref.eSet(ConditionModelPackage.Literals.EXPRESSION_PROCESS_REF__VALUE, EcoreUtil.resolve(proxy, resourceSet));
        }
    }
    return compareOp;
}
 
Example 13
Source File: CompilationTestHelper.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
protected void doLinking() {
	doIndex();
	for (Resource resource : sources) {
		EcoreUtil2.resolveLazyCrossReferences(resource, CancelIndicator.NullImpl);
	}
}
 
Example 14
Source File: CompilationTestHelper.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
protected void doLinking() {
	doIndex();
	for (Resource resource : sources) {
		EcoreUtil2.resolveLazyCrossReferences(resource, CancelIndicator.NullImpl);
	}
}
 
Example 15
Source File: ResourceValidatorImpl.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected void resolveProxies(final Resource resource, final CancelIndicator monitor) {
	EcoreUtil2.resolveLazyCrossReferences(resource, monitor);
}